How to read system.web section from web.config

后端 未结 3 2080
轻奢々
轻奢々 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:45

    I think accessing system.web is slightly different to accessing appSettings.

    Try this:

    string configPath = "/MyAppRoot";
    
    Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
    
    IdentitySection section = (IdentitySection)config.GetSection("system.web/identity");
    

    You need to cast the relevant section of system.web you're trying to access to a particular type.

提交回复
热议问题