views:

76

answers:

2

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>
A: 

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> 
Raj Kaimal
This doesn't seem to change anything. I still get the same error message.
NowYouHaveTwoProblems
+1  A: 

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://www.aspdotnetfaq.com/Faq/how-to-disable-web-config-inheritance-for-child-applications-in-subfolders-in-asp-net.aspx

http://msdn.microsoft.com/en-us/library/b6x6shw7.aspx

Fadrian Sudaman
This is an interesting approach. I was hoping to find a way to define my configuration setting to not inherit, but I might be able to change the default web.config to define the pertinent sections within a location section
NowYouHaveTwoProblems
+1 - I have used the location element to solve the exact the problem the author is experiencing. Just be careful though. Only wrap what you don't want inherited in the location tag. I wrapped most the web.config in the element and experienced an issue where the debugger would not attach to the process initially.
Aaron Daniels