「Web.config」の版間の差分

提供: MonoBook
ナビゲーションに移動 検索に移動
imported>Administrator
imported>Administrator
 
(同じ利用者による、間の1版が非表示)
9行目: 9行目:
 
     {
 
     {
 
         // Web.configが置いてあるディレクトリのパスを取得する。
 
         // Web.configが置いてあるディレクトリのパスを取得する。
         var path = HostingEnvironment.ApplicationPhysicalPath;
+
         var path = HostingEnvironment.ApplicationVirtualPath;
  
 
         // Web.configを開く。
 
         // Web.configを開く。
         Configuration webConfig = WebConfigurationManager.OpenMachineConfiguration(path);
+
         Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(path);
  
 
         // sessionStateエレメントを抽出する。
 
         // sessionStateエレメントを抽出する。
20行目: 20行目:
  
 
== 関連項目 ==
 
== 関連項目 ==
 +
* [[ASP.NET MVC]]
 
== 参考文献 ==
 
== 参考文献 ==
 
<references/>
 
<references/>
 
== 外部リンク ==
 
== 外部リンク ==
 
{{stub}}
 
{{stub}}

2012年4月2日 (月) 03:03時点における最新版

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");
    }

関連項目[編集 | ソースを編集]

参考文献[編集 | ソースを編集]

外部リンク[編集 | ソースを編集]