2010-09-06 47 views
9

是否有任何'很好'的方式通过使用WebConfigurationManager任何东西来读取IIS7的配置节组? 我试图读取授权部分,但WebConfigurationManager.GetSection()返回一个'IgnoredSection'实例。 这是我的代码看起来像......如何阅读system.webserver配置部分?

authSection = WebConfigurationManager.GetSection("system.webServer/security/authorization", HttpContext.Current.Request.Path) 

回答

5
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); 
ConfigurationSection cs = webConfig.GetSection("system.webServer"); 
if (cs != null) 
{ 
    XDocument xml = XDocument.Load(new StringReader(cs.SectionInformation.GetRawXml())); 
    ... 
} 
+0

如何阅读customheaders值? 我的web.config是如下 <添加名称= “X-内容类型-选项” 值= “nosniff”/> <添加名称=“X-Frame-Options”value =“SAMEORIGIN”/> ABB 2017-09-15 06:27:07