我正在尝试添加
<location inheritInChildApplications="false">
到我的父 Web 应用程序的 web.config,但它似乎不起作用。
我 parent 的 web.config
有:
<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>
我的子 Web 应用程序被设置为 IIS 中的应用程序,并且继承自父级的 web.config
,这导致了问题。
我到底应该把它放在哪里
<location inheritInChildApplications="false">
所以它会忽略所有不同的 web.config 设置?
最佳答案
正如前面答案的评论者提到的那样,您不能简单地添加以下行...
<location path="." inheritInChildApplications="false">
...就在 <configuration>
下面。相反,您需要包装要禁用继承的各个 web.config 部分。例如:
<!-- 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>
同时<clear />
可能适用于某些配置部分,但有些配置部分需要 <remove name="...">
指令,但其他人似乎也不支持。在这些情况下,设置 inheritInChildApplications="false"
可能是合适的。 .
关于asp.net - 使用inheritInChildApplications避免子Web应用程序中的web.config继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/782252/