2010-09-06 44 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