12

有没有什么“好”的方法可以通过使用 WebConfigurationManager 来读取 IIS7 的配置节组?我试图阅读授权部分,但 WebConfigurationManager.GetSection() 返回一个“IgnoredSection”实例。这就是我的代码的样子......

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

1 回答 1

8
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); 
ConfigurationSection cs = webConfig.GetSection("system.webServer");
if (cs != null)
{
    XDocument xml = XDocument.Load(new StringReader(cs.SectionInformation.GetRawXml()));
    ...
}
于 2014-05-28T18:33:52.390 回答