I have a content management application in the root of my website, and I\'m trying to use a different app (a billing application) under a sub-folder. Unfortunately, the web.
There is an attribute that you can use in the root web.config file to cause it not to have its contents become inherited by child applications.
inheritInChildApplications
Blog about inheritInChildApplications
MSDN article on ASP.NET Configuration File Hierarcy and Inheritance
Put the part of the config that is not for inheritance inside
<location inheritInChildApplications="false">
<NotInheritedConfigPart/>
</location>
Config sections seem to be impossible to not inherit, but other parts of configuration can be "commented" out like this and don't get inherited.
If you can use 2 separate application pools, you can completely stop inheritance by using an attibute enableConfigurationOverride="false"
in the applicationHost.config file as I described in this question: “Entry has already been added” - Two Separate App Pools
<add name="MyAppPool" enableConfigurationOverride="false" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" >
<processModel identityType="NetworkService" />
</add>
In my opinion every time I've struggled with this the answer ends up being effectively NO - and I'm leaving this here for my future self to find so he doesn't waste any more time on it.
I've found this to be a huge problem when you just want to add something as a virtual directory inside an existing site. With a complex web.config files I've always just ended up giving up and moving it to a different application altogether.
I would explicitly define all of the settings required - never assume that any setting is still set to the default value.
For example, if you're defining a connectionString include a <clear />
tag before the <add name=... />
, etc. For Membership define all of the attributes, including the cookie name. And so on.
It may make the file a bit bigger but it will definitely help you avoid the "but it worked on my box" scenario too :-)