Reputation: 133
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:
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>
Upvotes: 0
Views: 621
Reputation: 6465
Did you try using location element? Not sure if it works, but worth giving it a try. Put this in the web.config of the Testing project and try it out.
<location path="." inheritInChildApplications="false">
<MyApp setting="value" />
...
</MyApp>
</location>
Two links that talk about using location element
http://msdn.microsoft.com/en-us/library/b6x6shw7.aspx
Upvotes: 1
Reputation: 8304
In the web.config under /testing, do this:
<configuration>
<configSections>
<remove name="MyApp"/> <===========
<section name="MyApp" type="MyApp.ConfigurationSection"/>
</configSections>
<MyApp setting="value" />
<NestedSettingCollection>
<Item key="SomeKey" value="SomeValue" />
<Item key="SomeOtherKey" value="SomeOtherValue" />
</NestedSettingCollection>
</MyApp>
</configuration>
Upvotes: 0