What's the difference between the WebConfigurationManager and the ConfigurationManager?

前端 未结 4 1662
臣服心动
臣服心动 2020-11-27 03:32

What\'s the difference between the WebConfigurationManager and the ConfigurationManager?

When should I use one over the other?

4条回答
  •  囚心锁ツ
    2020-11-27 04:05

    WebConfigurationManger knows how to deal with configuration inheritance within a web application. As you know, there could be several web.config files in one applicaion - one in the root of the site and any number in subdirectories. You can pass path to the GetSection() method to get possible overridden config.

    If we'd looke at WebConfigurationManager with Reflector then things are clear:

    public static object GetSection(string sectionName)
    {
        ...
        return ConfigurationManager.GetSection(sectionName);
    }
    
    public static object GetSection(string sectionName, string path)
    {
        ...
        return HttpConfigurationSystem.GetSection(sectionName, path);
    }
    

提交回复
热议问题