Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

asp.net - How to stop inheritance of <configSections>in Web.Config

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...