Web.config
ナビゲーションに移動
検索に移動
Web.configから特定エレメントを抽出する[編集 | ソースを編集]
Web.configの各エレメントには「ConfigurationSection クラス (System.Configuration)」から派生したマッピングクラスが用意されている。
using System.Web.Hosting;
using System.Web.Configuration;
using System.Configuration;
public SessionStateSection GetSessionStateSection()
{
// Web.configが置いてあるディレクトリのパスを取得する。
var path = HostingEnvironment.ApplicationVirtualPath;
// Web.configを開く。
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(path);
// sessionStateエレメントを抽出する。
return = (SessionStateSection) webConfig.GetSection("system.web/sessionState");
}