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.
No new comments are allowed on this post.
Comments
No Limit List
I tried this, but the location tag DOES NOT HAVE a an inheritInChildApplication attribute
Farida
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
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
...the Remove tag:
<remove name="namespace.Properties.Settings.MyConnectionString" />
harshil patel
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
where is web.config file :(( I dont know please help me....
Mustafa CAKMAK
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
Awesome! Thanks!
Robert
How should you disable inheritance of ? This only applies to entries in
Robert
How should you disable inheritance of < configSections />? This only applies to entries in < System.Web />
qasssd
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
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
THANKS! Searched the world over for a answer.
Skip
Mayank
Gr8 solution...
Its work for application
Thomas Hansen
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
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
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
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
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! ;)
Dityo Nurasto
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
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
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!
湘江
谢谢你!
asp.net scripts
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
Thanks for sharing. This has saved me a ton of time!
Chris
Thanks for sharing this, just what I was looking for! Great problem solver for inheritance of themes!
xoperator
Thank you ! :)
T Vo
Thank you so much for this tip.
TV
Speaskken
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
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!
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
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