更新时间:2022-10-16 10:35:09
正如上一个答案的评论者所提到的,您不能简单地添加行...
...就在
下方.相反,您需要包装要禁用继承的各个 web.config 部分.例如:
<连接字符串></connectionStrings></位置><!-- 为 appSettings 启用继承 --><应用设置></appSettings><!-- 禁用 system.web 部分的继承 --><system.web><webParts></webParts><会员资格></会员资格><编译></编译></system.web></位置>
虽然
可能适用于某些配置部分,但有些部分需要
指令,还有其他人似乎也不支持.在这些情况下,设置 inheritInChildApplications="false"
可能是合适的.
I am trying to add
<location inheritInChildApplications="false">
to my parent web application's web.config but it doesn't seem to be working.
My parent's web.config
has:
<configuration>
<configSections>
</configSections>
// 10 or so custom config sections like log4net, hibernate,
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
<system.diagnostics>
</system.diagnostics>
<system.web>
<webParts>
</webParts>
<membership>
</membership>
<compilation>
</compilation>
</system.web>
<location ..>
<system.web>
</system.web>
</location>
<system.webServer>
</system.webServer>
My child web application is setup as an application in IIS, and is inheriting from the parent's web.config
which is causing problems.
Where exactly should I place the
<location inheritInChildApplications="false">
so it ignores all the various web.config settings?
As the commenters for the previous answer mentioned, you cannot simply add the line...
<location path="." inheritInChildApplications="false">
...just below <configuration>
. Instead, you need to wrap the individual web.config sections for which you want to disable inheritance. For example:
<!-- disable inheritance for the connectionStrings section -->
<location path="." inheritInChildApplications="false">
<connectionStrings>
</connectionStrings>
</location>
<!-- leave inheritance enabled for appSettings -->
<appSettings>
</appSettings>
<!-- disable inheritance for the system.web section -->
<location path="." inheritInChildApplications="false">
<system.web>
<webParts>
</webParts>
<membership>
</membership>
<compilation>
</compilation>
</system.web>
</location>
While <clear />
may work for some configuration sections, there are some that instead require a <remove name="...">
directive, and still others don't seem to support either. In these situations, it's probably appropriate to set inheritInChildApplications="false"
.