0

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.

monstro
  • 6,254
  • 10
  • 65
  • 111

1 Answers1

0

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"];
EM0
  • 5,369
  • 7
  • 51
  • 85