You simply cannot use <location path="." inheritInChildApplications="false">
in certain parts of your web.config in order to tell it to ignore inheritance of certain sections (you'll get errors such as 'inheritInChildApplications attribute is not declared' and so fourth if you try putting it in sections where it's not supported).
For example you can't use it before or inside <configSections>
. You can for example wrap your <system.web>
tag in the location tag but I need to stop inheritance of anything in <configSections>
and I do not see a way to do this.
My sub application is inheriting some of the same config settings that my parent app's web config has in IIS 7 in the tree. I see no way to put a <clear/>
either in the configSecion tag as it's an invalid tag if you try to add it there.
How do you tell it to ignore that section?
In order to prevent root settings to be inherited, use inheritInChildApplications attribute in location tag. The location path in the example above is empty. It means that this setting will be applied to the level of the config file and below it.
The InheritInChildApplications property represents the inheritInChildApplications attribute of a location element in a configuration file.
This very same question was asked multiple times on SO as well as many other forums and answer was more or less the same, No you cannot use location/clear/remove for configsection.
Microsoft even replied on their thread as follows.
Posted by Microsoft on 7/23/2009 at 5:40 PM
<clear /> and <remove />
were never implemented for configSections and sectionGroups because of the difficulty involved attempting to merge different definitions of the same section-handlers and section groups.
We considered adding this type of functionality for the VS 2010 release, but we decided against it for two reasons.
The first one being the additional complexity it brings, in large part because section handlers and section groups are used to bootstrap the configuration system. As a result allowing for merge semantics in the middle of bootstrapping the configuration system is a non-trivial problem to solve.
The second reason is that usually section handlers and section group definitions are made in two distinct places - an initial set of registrations up in the root configuration files, and then an additive set of registrations in application level web.config. That doesn't mean a scenario where a developer wants to modify handler definitions isn't valid - its just a low likelihood scenario. Thank you for taking the time though to submit your suggestion via Connect!
Check out this SO thread, which simple states avoid using conflicting section groups.
However, Nairman suggests following,
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
How to prevent inheritance for web.config file for "configSections"?
What you could do is make that folder an application, do a reverse proxy (using IIS 7's URL Rewrite module) on it to another internal site and it should keep configs completely separate.
For example one of ours for a proxy redirect is: Matches the pattern using Wildcards * to rewrite URL http://127.0.0.1:8080/{R:1}
A terrible idea to be honest (I hate dirty methods of getting things done), you should be able to tell IIS you want a clean slate on a child application's config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With