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
523 views
in Technique[技术] by (71.8m points)

asp.net - Disable web.config inheritance?

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.config of the root site is interfering with the sub-app.

Is there a way to just disable web.config inheritance for a sub-folder?

Update: As linked by Stephen Burris, using the <location> tag can prevent inheritance for part of the web config, as follows:

<?xml version="1.0"?>
<configuration>
<configSections>
    ....
</configSections>
<location path="." inheritInChildApplications="false">
    <appSettings>
        ....
    </appSettings>
    <connectionStrings/>
    <system.web>
        ....
    </system.web>
    <system.codedom>
        ....
    </system.codedom>
    <system.webServer>
        ....
    </system.webServer>
</location>
<runtime>
    ....
</runtime>
</configuration>

The <configSections> and <runtime> sections will not accept being enclosed in the tag...so I guess this only does most of the job. Anybody know how to do it better?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.


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

...