Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read system.webserver configuration section?

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)
like image 217
Maxolidean Avatar asked Sep 06 '10 13:09

Maxolidean


People also ask

What is system webServer in Web config?

The <system. webServer> element specifies the root element for many of the site-level and application-level configuration settings for Internet Information Services (IIS) 7 in the ApplicationHost. config file, and contains configuration elements that define the settings used by the Web server engine and modules.

What is configuration in Web config?

A configuration file (web. config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way you can configure settings independently from your code.

What is IIS explain its configuration?

Internet Information Services (IIS) 7 and later use an XML-based configuration system for storing IIS settings which replaces the metabase that was used in IIS 6.0 and earlier. This new configuration system was introduced with ASP.NET and is based on a hierarchical system of management system that uses *. config files.


1 Answers

Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); 
ConfigurationSection cs = webConfig.GetSection("system.webServer");
if (cs != null)
{
    XDocument xml = XDocument.Load(new StringReader(cs.SectionInformation.GetRawXml()));
    ...
}
like image 55
user2316116 Avatar answered Oct 19 '22 05:10

user2316116