【问题标题】:How to retrieve non <appSettings> keys from the web.config?如何从 web.config 中检索非 <appSettings> 键?
【发布时间】:2012-03-25 06:59:47
【问题描述】:

我的 web.config 中有以下内容:

<configuration>
    <system.web>
        <httpRuntime executionTimeout="180"/>
    </system.web>
</configuration>

是否有 .NET 内置方法来检索 executionTimeout 值?也许通过 ConfigurationManager 对象集?我没有看到任何明显的东西。

【问题讨论】:

    标签: c# asp.net .net web-config


    【解决方案1】:

    可以使用GetSection检索任何部分

    var httpRuntimeSection = ConfigurationManager.GetSection("system.web/httpRuntime") as 
    HttpRuntimeSection;
    
    //httpRuntimeSection.ExecutionTimeout
    

    ExecutionTimeout

    在 Web 应用中,我们可以使用 WebConfigurationManager,它也有类似的 API - GetSection

    ConfigurationManager vs. WebConfigurationManager

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 2017-10-19
      • 2010-09-08
      • 2014-05-03
      • 1970-01-01
      相关资源
      最近更新 更多