「Web.config」の版間の差分
imported>Administrator ページの作成:「== Web.configから特定エレメントを抽出する == <source lang="csharp"> // Web.configが置いてあるディレクトリのパスを取得する。 v...」 |
imported>Administrator |
||
| 1行目: | 1行目: | ||
== Web.configから特定エレメントを抽出する == | == Web.configから特定エレメントを抽出する == | ||
Web.configの各エレメントには「[[ConfigurationSection クラス (System.Configuration)]]」から派生したマッピングクラスが用意されている。 | |||
<source lang="csharp"> | <source lang="csharp"> | ||
using System.Web.Hosting; | |||
using System.Web.Configuration; | |||
using System.Configuration; | |||
// Web. | public SessionStateSection GetSessionStateSection() | ||
{ | |||
// Web.configが置いてあるディレクトリのパスを取得する。 | |||
var path = HostingEnvironment.ApplicationPhysicalPath; | |||
// Web.configを開く。 | |||
Configuration webConfig = WebConfigurationManager.OpenMachineConfiguration(path); | |||
// sessionStateエレメントを抽出する。 | |||
return = (SessionStateSection) webConfig.GetSection("system.web/sessionState"); | |||
} | |||
</source> | </source> | ||
2012年3月30日 (金) 08:07時点における版
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.ApplicationPhysicalPath;
// Web.configを開く。
Configuration webConfig = WebConfigurationManager.OpenMachineConfiguration(path);
// sessionStateエレメントを抽出する。
return = (SessionStateSection) webConfig.GetSection("system.web/sessionState");
}