14

I have following in my parent web applications config file

<configuration>
  <configSections>
    <sectionGroup name="testmodule">
      <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
    </sectionGroup>
  </configSections>
</configuration>

i want to prevent child subfolders from inheriting this config section where should i put <location path="." inheritInChildApplications="false">, since config sections should be first child element of configuration file

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
DSharper
  • 3,177
  • 9
  • 29
  • 47

5 Answers5

10

This has been answered a couple of times on SO, but incorrectly in my opinion.

The docs, are pretty clear (1)(2):

The following example shows how to use this attribute in a configuration file to specify that the settings defined in the location element for the root of a Web site should not be inherited by child applications:

The InheritInChildApplications property applies only to location-specific configuration settings.

To answer your question, this should suffice:

<configuration>
...
<sectionGroup name="testmodule">
    <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
...
<location path="." inheritInChildApplications="false">
    <testModule>
    ....
    </testModule>
</location>

(1) - http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.inheritinchildapplications.aspx

(2) - http://msdn.microsoft.com/en-us/library/ms178692.aspx

Nariman
  • 6,368
  • 1
  • 35
  • 50
  • Thanks Nariman for reply,sorry this doesn't work, issue your suggesion only prevents inheritance of of ... section, the issue is child subfolder application of root web application has section group with testmodule but comes from different assembly. so when i add
    to the child subfolder web config issue still arises
    – DSharper Oct 28 '10 at 06:00
  • I'm not sure that you can have the same section defined differently in a sub-folder; you could make that sub-folder a stand-alone virtual application, in which case it wouldn't inherit any of the settings from the parent; in this scenario, it would also execute in its own app pool; if you don't have InProc dependencies, that's an option as well. – Nariman Oct 29 '10 at 15:56
7

Seems to be no solution for this currently, should avoid using conflicting section groups in web.config file.

DSharper
  • 3,177
  • 9
  • 29
  • 47
1

If you use a different name in the conflicting child section it will not clash with the parent and you can reference both sections in their respective web.config files using the different names..

its not perfect but its a work around i've used with success....

mickdelaney
  • 1,045
  • 1
  • 10
  • 16
0

We're getting errors about duplicate configuration directives on the one of our apps. After investigation it looks like it's because of this issue.

In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.

web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.

However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains these config sections.

The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the node.

The only solution I've been able to find is to remove the config sections from the parent web.config, and then either

  1. Determine that you didn't need them in your root application, or
  2. Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)
Josh
  • 7,232
  • 8
  • 48
  • 75
  • 1
    If you have a 3.5 parent site and a 4.0 child site, one hack is to move the conflicting parent SectionGroup into C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Web.config. The 4.0 child site won't merge in anything from there. http://www.asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc252995490. – mikebridge Feb 27 '13 at 19:44
0

i have the same situation than you as my root Application is using an AppPool of .net 2.0 and child AppPool is .Net 4.0. I solved using the suggestion in "Entry has already been added" - Two Separate App Pools, by setting both AppPools to enableConfigurationOverride="false" it works like a charm.

nikademus
  • 63
  • 6