Stopping ASP.NET web.config inheritance

If you are only ever running one ASP.NET application on a website this is not an issue. However, if you are running a site which may have an application at the root and other separate applications running in sub or virtual directories, then Settings inheritance could be a problem.

You can read more about how config files get inherited on msdn but here's a tip for stopping settings in the root app from getting inherited. The <location> tag is the only tag I've come across which has the inheritInChildApplications attribute. So to target the main <system.web> just wrap it in the location tag as seen below. 

<location path="." inheritInChildApplications="false">
<system.web>
 ...
</system.web>
</location>

Other Notes:
Although I think the inheritance is in general a good feature to have, especially for inheriting down things such as security settings.  It can even support locking certain settings for child applications, but things can be problematic if the child application doesn't share the same libraries, modules, handlers, masterpages or themes.

Most collections in the web.config have the <remove> tag or <clear> tag to remove irrelevant modules or handlers in the child app.  The problems I've found occur with settings relating to the <pages> tag, which most items in it don't support <remove>. This means if your child applications doesn't share or have the same registered controls, masterpages or themes then you are probably going to have issues or be forced to specify the settings on a per-page basis.  This is where the inheritInChildApplications="false" really comes in handy.

Print | posted on Wednesday, May 16, 2007 1:11 PM

&uot&uot

Comments on this post

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Thank you for the article. This was exactly what I was looking for and MS doesn't seem to give to many hints on the MSDN library about how to stop the inheritance.

Ryan
Left by Ryan on Jul 10, 2007 11:24 PM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Thanks a lot. My ASP.NET enterprise manager stop working when installing subtext.

My webhosting seems locking CustomError which make me frustated to debug subtext. I want to override the machine.config, is there anyway to do this?
Left by Dityo Nurasto on Aug 18, 2007 4:41 PM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Thanks for sharing this, just what I was looking for! Great problem solver for inheritance of themes!
Left by Chris on Feb 07, 2008 2:53 AM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Thanks for sharing. This has saved me a ton of time!
Left by Nathan Harkenrider on Feb 27, 2008 12:32 PM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
谢谢你!
Left by 湘江 on Mar 15, 2008 4:25 PM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
I'm new to iis and .net administration and had been having trouble with virtual directories with vendor app's for the last 4 months. Turns out it was the sql role manager we had configured and I threw your location config in and it's solved every problem I'd been having.

Thanks!
Left by tony on May 22, 2008 4:33 AM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Just two days ago I had a client move my script to avoid inheriting stuff from "parent" site. Problem solved, but now when I know this I will now be able to put this into the default config file and not see this kind of problem again. So thanks! :)
Left by asp.net scripts on Jul 03, 2008 5:39 AM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
THANKS! Searched the world over for a answer.

Skip
Left by Skip Floyd on Jul 10, 2008 1:15 AM

# re: Stopping ASP.NET web.config inheritance

Requesting Gravatar...
Gr8 solution...
Its work for application
Left by Mayank on Jul 11, 2008 2:52 AM

Your comment:

 (will show your gravatar)
 
Please add 5 and 1 and type the answer here: