How to read system.web section from web.config

后端 未结 3 2082
轻奢々
轻奢々 2021-02-13 09:37

Should be simple, but whatever I try returns null:

const string key = \"system.web\";

var sectionTry1 = WebConfigurationManager.GetSection(key);

var sectionTry         


        
3条回答
  •  再見小時候
    2021-02-13 09:38

    Was being an idiot - system.web is not a config section but a config group. If I change the key to an actual section, then both methods work fine. Here's the one using ConfigurationManager:

    const string outputCacheSettingsKey = "system.web/caching/outputCacheSettings";           
    
    var outputCacheSettingsSection = ConfigurationManager.GetSection(outputCacheSettingsKey) as OutputCacheSettingsSection;
    

提交回复
热议问题