我正在尝试添加
<location inheritInChildApplications="false">
到我的父网络应用程序的web.config但它似乎没有工作。
我父母的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>
我的子网页应用程序在IIS中设置为应用程序,并且继承了导致问题的父级web.config
。
我应该在哪里放置
<location inheritInChildApplications="false">
所以它忽略了所有各种web.config设置?
答案 0 :(得分:194)
正如前面提到的答案的评论者所说,你不能简单地添加一行......
<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"
可能是合适的。
答案 1 :(得分:62)
它需要直接位于根<configuration>
节点下,您需要设置这样的路径:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
处理配置继承的更好方法是在子配置中使用<clear/>
,无论您何时不想继承。因此,如果您不想继承父配置的连接字符串,您可以执行以下操作:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
答案 2 :(得分:22)
我把所有东西都放进去了:
<location path="." inheritInChildApplications="false">
....
</location>
除外:<configSections/>
,<connectionStrings/>
和<runtime/>
。
在某些情况下,我们不想继承<configSections />
的某些部分,但我们无法将<section/>
标记放入<location/>
,因此我们必须创建一个{ {1}}并将我们不需要的部分放入该组中。稍后可以将节组插入位置标记。
所以我们必须改变这个:
<secionGroup />
分为:
<configSections>
<section name="unwantedSection" />
</configSections>
答案 3 :(得分:8)
我们在最近向我们的某个开发环境发布代码后收到了与此相关的错误。我们有一个应用程序是另一个应用程序的子代。直到昨天,这种关系一直很好。直到昨天。
问题:
由于输入了重复的密钥,我们得到了黄色堆栈跟踪错误。这是因为子应用程序和父应用程序的web.config都具有此密钥。但这种存在多年来没有变化。为什么现在突然出现问题呢?
解决方案:
这从来不是问题的原因是因为键AND值总是相同的。昨天我们更新了SQL连接字符串,以在连接字符串中包含Application Name。这使得字符串变得独一无二,突然之间开始失败。
如果没有对此确切原因进行任何研究,我必须假设当子应用程序继承父web.config值时,它会忽略相同的键/值对。
我们能够像这样包装连接字符串来解决它
<location path="." inheritInChildApplications="false">
<connectionStrings>
<!-- Updated connection strings go here -->
</connectionStrings>
</location>
编辑:我忘了提到我在PARENTS web.config中添加了这个。我没有必要修改孩子的web.config。
感谢大家对此的帮助,救了我们的屁股。
答案 4 :(得分:7)
如果(据我所知)你试图在你的子应用程序的web配置中完全阻止继承,我建议你避免在web.config中使用该标记。
而是创建一个新的apppool并编辑applicationHost.config文件(位于%WINDIR%\ System32 \ inetsrv \ Config和%WINDIR%\ SysWOW64 \ inetsrv \ config中)。
您只需找到您的apppool的条目,并添加属性enableConfigurationOverride="false"
,如下例所示:
<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
<processModel identityType="NetworkService" />
</add>
这将避免MyAppPool服务的应用程序中的配置继承。
利玛
答案 5 :(得分:2)
这是location
标记上的微软页面:http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx
对某些人来说可能会有所帮助。
答案 6 :(得分:1)
我们在其中一个应用上遇到有关重复配置指令的错误。 经过调查后,它看起来像是this issue。
简而言之,我们的根网站是ASP.NET 3.5(添加了特定库的2.0),我们有一个ASP.NET 4.0的子应用程序。
web.config继承导致ASP.NET 4.0子应用程序继承父ASP.NET 3.5应用程序的web.config文件。
但是,ASP.NET 4.0应用程序的全局(或“根”)web.config,它位于C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Config \ web.config和C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ web.config(取决于你的位数),已包含这些配置部分。
ASP.NET 4.0应用程序然后尝试将根ASP.NET 4.0 web.config和父web.config(用于ASP.NET 3.5应用程序的那个)合并在一起,并在节点中运行重复项。
我能找到的唯一解决方案是从父web.config中删除配置部分,然后