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 appli...

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.

General Code Snippets ASP.NET
Posted by: Brendan Kowitz
Last revised: 17 May, 2007 01:11 AM History

Comments

No Limit List
No Limit List
09 Apr, 2010 01:47 AM

I tried this, but the location tag DOES NOT HAVE a an inheritInChildApplication attribute

Farida
Farida
04 Mar, 2010 09:23 AM

hello,
I couldn't find "inheritInChildApplications" attribute of the Location tag, rather I could get only "allowOverride" attribute.

plz let me know how and where can I find this.

Thanks & regrds,
Farida

Jason B
Jason B
21 Feb, 2009 05:45 PM

I have an issue with trying to stop ConnectionStrings settings. My top-level and sub apps may reference the same data assembly. However, my top app may need to save to one server where the sub-apps may save to another. Right now, the only solution I could find is to use the


tag if the value differed.
Any shortcuts to stop the connectionstrings section from inheriting?

Jason B
Jason B
21 Feb, 2009 05:46 PM

...the Remove tag:
<remove name="namespace.Properties.Settings.MyConnectionString" />

harshil patel
harshil patel
03 Feb, 2009 05:14 PM

Thanks a lot, i was looking for this solutions since many weeks, but i found many web sites saying inheritInChildApplications, and some saying allowOverride, i would like to actuallyknow why there are two different attributes with opposite meanings ?

That and really helped me solve my problem, i didn;t think about this, probably i was so messed up with the inheritance tags.

Thanks a lot, u saved me tonnes of unproductive time.

Mustafa CAKMAK
Mustafa CAKMAK
31 Mar, 2009 10:25 AM

where is web.config file :(( I dont know please help me....

Mustafa CAKMAK
Mustafa CAKMAK
31 Mar, 2009 01:27 PM

Hello.
I added this



include web.config file. but I have a question. which path add in "." this area?? May you show me an example path, please...
thanks...

Matt
Matt
10 Apr, 2009 03:08 PM

Awesome! Thanks!

Robert
Robert
23 Apr, 2009 10:06 AM

How should you disable inheritance of ? This only applies to entries in

Robert
Robert
23 Apr, 2009 10:08 AM

How should you disable inheritance of < configSections />? This only applies to entries in < System.Web />

qasssd
qasssd
01 Jul, 2009 06:47 AM

Good answer, I am looking for the solution of the same question. Find the movies or mp3 you are looking for at music-and-soundtracks.com the most comprehensive source for free-to-try files downloads on the Web

Derek
Derek
20 Aug, 2009 02:47 PM

One problem with this solution(currently googling for a solution and read through these comments to see if someone had listed one)-- VS2008 does not properly debug if there's a tag in it.... Try it-- try to debug your parent application with the tag in your web.config, and notice that the debugger never starts... Remove the tag, and voilla...

--
Derek

Skip Floyd
Skip Floyd
10 Jul, 2008 01:15 PM

THANKS! Searched the world over for a answer.

Skip

Mayank
Mayank
11 Jul, 2008 02:52 PM

Gr8 solution...
Its work for application

01 Sep, 2008 07:19 AM

Great writeup, I didn't know :)
I've bookmarked this post now and will implement this to remove the needs for deploying my UrlRewrite DLL also on the Ajax samples at our site which curently is a need :)

Amit Bhatnagar
Amit Bhatnagar
03 Sep, 2008 03:56 PM

Hello,

Good article.

What if I have 3 applications underneath the main one, and 2 need to inherit the config values, while 1 doesn't. How do I handle that scenario?

Thanks, and best regards,
- Amit.

Conrad
Conrad
06 Sep, 2008 10:26 PM

OMG Thank you! I had a (revenue producing) production application which was dead for over an hour because of this. I has three crappy backup plans, but your site helped me to avoid them all. Thank you, thank you, thank you!

Mark
Mark
09 Oct, 2008 10:58 AM

Very good tip. I had no idea this was possible but your article is concise and well written. With the use of locations to target directories, it's clear that web.config inheritance can be applied selectively.

Thank you!

Ed
Ed
24 Nov, 2008 05:45 AM

Thanks...this works great!

One point...probably obvious to most...

The tag goes in the root or top level web.config file that you do not want the settings to trickle down from.

For some silly reason I focused on the lower level web.config in my virtual folder and the tag did no good there of course. Wasted a few hours before the light bulb finally came on for me! ;)

19 Aug, 2007 04:41 AM

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?

Ryan
Ryan
11 Jul, 2007 11:24 AM

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

tony
tony
22 May, 2008 04:33 PM

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!

湘江
湘江
16 Mar, 2008 04:25 AM

谢谢你!

03 Jul, 2008 05:39 PM

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! :)

Nathan Harkenrider
Nathan Harkenrider
28 Feb, 2008 01:32 AM

Thanks for sharing. This has saved me a ton of time!

Chris
Chris
07 Feb, 2008 03:53 PM

Thanks for sharing this, just what I was looking for! Great problem solver for inheritance of themes!

xoperator
xoperator
27 Dec, 2010 10:21 AM

Thank you ! :)

T Vo
T Vo
09 Feb, 2011 06:57 PM

Thank you so much for this tip.
TV

Speaskken
Speaskken
26 Jun, 2011 01:50 AM

Viokin Medicine http://www.walkdiggler.com/ - plavix 75 mg Not all patients will experience these side effects and most find that they subside on their own within a few days. cheap plavix online

sweegortelo
sweegortelo
25 Jun, 2011 06:33 AM

Drug Abuse In Teens Statistics http://www.thecouponclass.com/ - soma 350 mg Soma is also used to treat many musculoskeletal conditions when a doctor finds that it is the proper medication for the treatment of the condition. http://www.thecouponclass.com/ - soma no prescription

Funka!
Funka!
29 Apr, 2011 06:01 PM

Wonderful! Thank you!

For people indicating there is no inheritInChildApplication attribute on the location tag, it actually does exist and work, but Visual Studio won't show you for some reason and will complain. Just ignore the complaints.

Pailtellaflef
Pailtellaflef
25 Jun, 2011 10:04 PM

Drugs For Depression And Anxiety http://www.supercheapfags.com/ - generic eszopiclone You should not take Lunesta if you do not have at least seven or eight hours to devote to sleeping. http://www.supercheapfags.com/ - buy lunesta online

No new comments are allowed on this post.