ASP.NET configuration inheritance

Posted by NowYouHaveTwoProblems on Stack Overflow See other posts from Stack Overflow or by NowYouHaveTwoProblems
Published on 2010-05-02T22:22:49Z Indexed on 2010/05/02 22:27 UTC
Read the original article Hit count: 142

Filed under:
|

I have an ASP.NET application that defines a custom configuration section in web.config.

Recently I had a customer who wanted to deploy two instances of the application (for testing in addition to an existing production application).

The configuration chosen by the customer was:

  • foo.com - production application
  • foo.com/Testing - test application

In this case, the ASP.NET configuration engine decided to apply the settings at foo.com/web.config to foo.com/Testing/web.config.

Thankfully this caused a configuration error because the section was redefined at the second level rather than giving the false impression that the two web applications were isolated.

What I would like to do is to specify that my configuration section is not inherited and must be re-defined for any web application that requires it but I haven't been able to find a way to do this.

My web.config ends up something like this

<configuration>
  <configSections>
    <section name="MyApp" type="MyApp.ConfigurationSection"/>
  </configSections>
  <MyApp setting="value" />
    <NestedSettingCollection>
      <Item key="SomeKey" value="SomeValue" />
      <Item key="SomeOtherKey" value="SomeOtherValue" />
    </NestedSettingCollection>
  </MyApp>
</configuration>

© Stack Overflow or respective owner

Related posts about web.config

Related posts about ASP.NET