读取web.config文件的值

时间:2017-09-14 12:09:19

标签: asp.net-mvc iis c#-4.0 iis-7 web-config

我想读取web.config文件的不同部分的值。

例如

<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" requestValidationMode="4.5" 
maxRequestLength="102400" />
<pages validateRequest="true"></pages>
</system.web>

在这个system.web部分,我想阅读httpRuntime requestValidationMode    值。在页面中,我想读取validateRequest的值。

另外,我想读取自定义标题的值

 <httpProtocol>
  <customHeaders>
    <add name="X-Content-Type-Options" value="nosniff" />
    <add name="X-Frame-Options" value="SAMEORIGIN" />
    <remove name="X-Powered-By" />
    <add name="X-XSS-Protection" value="1; mode=block" />
  </customHeaders>
</httpProtocol>

1 个答案:

答案 0 :(得分:0)

我相信你想要这样的东西

<compilation debug="true" ...>

对于其他值,您必须搜索该值的存储位置。例如

HttpContext.Current.IsDebuggingEnabled

存储在这里

System.Web.Configuration.PagesSection
System.Web.Configuration.HttpHandlersSection

此外,许多节类型都存储在System.Web.Configuration

"window.restoreWindows": "all"

你也可以使用GetSection()来检索它们。

相关问题