「Web.config」の版間の差分

imported>Administrator
ページの作成:「== Web.configから特定エレメントを抽出する == <source lang="csharp"> // Web.configが置いてあるディレクトリのパスを取得する。 v...」
 
imported>Administrator
 
(同じ利用者による、間の2版が非表示)
1行目: 1行目:
== Web.configから特定エレメントを抽出する ==
== Web.configから特定エレメントを抽出する ==
Web.configの各エレメントには「[[ConfigurationSection クラス (System.Configuration)]]」から派生したマッピングクラスが用意されている。
<source lang="csharp">
<source lang="csharp">
     // Web.configが置いてあるディレクトリのパスを取得する。
     using System.Web.Hosting;
     var path = HostingEnvironment.ApplicationPhysicalPath;
    using System.Web.Configuration;
     using System.Configuration;


     // Web.configを開く。
     public SessionStateSection GetSessionStateSection()
    Configuration webConfig = WebConfigurationManager.OpenMachineConfiguration(path);
    {
        // Web.configが置いてあるディレクトリのパスを取得する。
        var path = HostingEnvironment.ApplicationVirtualPath;


    // sessionStateエレメントを抽出する。
        // Web.configを開く。
    var config = (SessionStateSection) webConfig.GetSection("system.web/sessionState");
        Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(path);
 
        // sessionStateエレメントを抽出する。
        return = (SessionStateSection) webConfig.GetSection("system.web/sessionState");
    }
</source>
</source>


== 関連項目 ==
== 関連項目 ==
* [[ASP.NET MVC]]
== 参考文献 ==
== 参考文献 ==
<references/>
<references/>
== 外部リンク ==
== 外部リンク ==
{{stub}}
{{stub}}