Split appSettings into multiple sections / files?

570 Views Asked by At

Can I split appSettings into multiple external config files and include them in main web.config?

Here is what I have tried, but its not working :(

In web.config I defined a new section:

<configSections>
    <section name="ssoConfiguration" type="System.Configuration.NameValueSectionHandler"/>
</configSections>

below I have this section:

<ssoConfiguration>
    <add key="SSOEnabled" value="true"/>
</ssoConfiguration>

When I call System.Configuration.ConfigurationManager.AppSettings["SSOEnabled"] it returns null.

Any ideas why?

Also, I will have multiple sections with such appSettins - is it possible to define them in multiple external config files and get them included in main web.config?

Thank you.

1

There are 1 best solutions below

0
EM0 On

Because you're accessing AppSettings, but the "SSOEnabled" setting is in another section ("ssoConfiguration"). Try

var ssoConfiguration = (NameValueCollection)ConfigurationManager.GetSection("ssoConfiguration")
var ssoEnabled = ssoConfiguration["SSOEnabled"];