How to read system.webserver configuration section?
Asked Answered
M

1

15

Is there any 'nice' way to read configuration section group of IIS7 by using WebConfigurationManager o anything? I tried to read the authorization section but WebConfigurationManager.GetSection() returns an 'IgnoredSection' instance. This is what my code looks like...

authSection = WebConfigurationManager.GetSection("system.webServer/security/authorization", HttpContext.Current.Request.Path)
Mannes answered 6/9, 2010 at 13:25 Comment(0)
G
9
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); 
ConfigurationSection cs = webConfig.GetSection("system.webServer");
if (cs != null)
{
    XDocument xml = XDocument.Load(new StringReader(cs.SectionInformation.GetRawXml()));
    ...
}
Giuditta answered 28/5, 2014 at 18:33 Comment(2)
how to read customheaders values? My web.config is as below <system.webServer> <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> </system.webServer>Zaxis
@ABB Have a look at this answer for an example: https://mcmap.net/q/436165/-how-to-read-system-value-from-web-config-and-use-in-asp-net-mvc-c-methodIsometric

© 2022 - 2024 — McMap. All rights reserved.