I am trying to add
我想补充一点
<location inheritInChildApplications="false">
to my parent web application's web.config but it doesn't seem to be working.
到我的父web应用程序的web。配置,但似乎不工作。
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.
我的子web应用程序在IIS中被设置为应用程序,并从父web继承。配置导致问题。
Where exactly should I place the
我到底应该在哪里的
<location inheritInChildApplications="false">
so it ignores all the various web.config settings?
所以它忽略了各种各样的网络。配置设置?
7 个解决方案
#1
183
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:
…略低于 <配置> 。相反,您需要包装单独的web。要禁用继承的配置节。例如:
<!-- 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"
.
虽然 <清楚> 可能为一些配置的部分工作,有一些,而不是需要一个 <删除name = "…"> 指令,还有一些似乎不支持。在这些情况下,它可能是适当的设置inheritInChildApplications = " false "。
#2
58
It needs to go directly under the root <configuration>
node and you need to set a path like this:
它需要直接在根 <配置> 节点,您需要设置一个路径是这样的:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
A better way to handle configuration inheritance is to use a <clear/>
in the child config wherever you don't want to inherit. So if you didn't want to inherit the parent config's connection strings you would do something like this:
处理配置继承的更好方法是在不希望继承的地方在子配置中使用
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
#3
18
I put everything into:
我把一切都放在:
<location path="." inheritInChildApplications="false">
....
</location>
except: <configSections/>
, <connectionStrings/>
and <runtime/>
.
除了:
There are some cases when we don't want to inherit some secions from <configSections />
, but we can't put <section/>
tag into <location/>
, so we have to create a <secionGroup />
and put our unwanted sections into that group. Section groups can be later inserted into a location tag.
有些情况下,我们不希望继承
So we have to change this:
所以我们必须改变这一点:
<configSections>
<section name="unwantedSection" />
</configSections>
Into:
成:
<configSections>
<sectionGroup name="myNotInheritedSections">
<section name="unwantedSection" />
</sectionGroup>
</configSections>
<location path="." inheritInChildApplications="false">
<myNotInheritedSections>
<unwantedSection />
</myNotInheritedSections>
</location>
#4
7
We were getting an error related to this after a recent release of code to one of our development environments. We have an application that is a child of another application. This relationship has been working fine for YEARS until yesterday.
在最近向我们的一个开发环境发布代码之后,我们遇到了与此相关的错误。我们有一个应用程序是另一个应用程序的子应用程序。直到昨天,这种关系一直都很好。
The problem:
We were getting a yellow stack trace error due to duplicate keys being entered. This is because both the web.config for the child and parent applications had this key. But this existed for many years like this without change. Why all of sudden its an issue now?
问题是:由于输入了重复的键,我们得到了一个黄色的堆栈跟踪错误。这是因为这两个网站。子应用程序和父应用程序的配置具有此键。但这种情况已经持续了很多年,没有改变。为什么现在突然成了问题?
The solution:
The reason this was never a problem is because the keys AND values were always the same. Yesterday we updated our SQL connection strings to include the Application Name in the connection string. This made the string unique and all of sudden started to fail.
解决方案:这不是问题的原因是键和值总是相同的。昨天我们更新了SQL连接字符串,将应用程序名称包含在连接字符串中。这使得字符串变得唯一,并且突然开始失败。
Without doing any research on the exact reason for this, I have to assume that when the child application inherits the parents web.config values, it ignores identical key/value pairs.
没有做任何研究确切的原因,我不得不认为当孩子应用程序继承了父母。配置值,它忽略了相同的键/值对。
We were able to solve it by wrapping the connection string like this
我们可以通过像这样封装连接字符串来解决它
<location path="." inheritInChildApplications="false">
<connectionStrings>
<!-- Updated connection strings go here -->
</connectionStrings>
</location>
Edit: I forgot to mention that I added this in the PARENTS web.config. I didn't have to modify the child's web.config.
编辑:我忘了提到我添加这个父母web . config。我没有修改孩子的web . config。
Thanks for everyones help on this, saved our butts.
谢谢大家的帮助,救了我们的屁股。
#5
4
If (as I understand) you're trying to completely block inheritance in the web config of your child application, I suggest you to avoid using the tag in web.config. Instead create a new apppool and edit the applicationHost.config file (located in %WINDIR%\System32\inetsrv\Config and %WINDIR%\SysWOW64\inetsrv\config). You just have to find the entry for your apppool and add the attribute enableConfigurationOverride="false"
like in the following example:
如果(正如我所理解的)您试图完全阻止子应用程序的web配置中的继承,我建议您避免在web.config中使用标记。相反,创建一个新的apppool并编辑applicationHost。配置文件(位于%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>
This will avoid configuration inheritance in the applications served by MyAppPool.
这将避免在appmypool服务的应用程序中继承配置。
Matteo
马特奥
#6
2
This is microsoft's page on the location
tag: http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx
这是微软在地址标签上的页面:http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx。
It may be helpful to some folks.
有些人可能会有帮助。
#7
1
We're getting errors about duplicate configuration directives on the one of our apps. After investigation it looks like it's because of this issue.
我们错误的重复配置指令我们的应用程序之一。经调查看来,因为这个问题。
In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.
简而言之,我们的根网站是ASP。NET 3.5(即添加了特定库的2.0),我们有一个子应用程序,即ASP。NET 4.0。
web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.
网络。配置继承导致ASP。继承web的NET 4.0子应用程序。父ASP的配置文件。NET 3.5的应用程序。
However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains these config sections.
然而,ASP。NET 4.0应用程序的全局(或“根”)web。配置,它驻留在Microsoft.NET \ Framework \ C:\Windows\ v4.0.30319 \ config \ web。配置和C:\Windows\ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ web。配置(取决于您的位),已经包含了这些配置部分。
The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the node.
ASP。NET 4.0应用程序试图将根ASP合并在一起。NET 4.0 web。配置和父web。配置(一个ASP的配置。NET 3.5 app),并在节点中运行。
The only solution I've been able to find is to remove the config sections from the parent web.config, and then either
我能找到的唯一解决方案是从父web中删除配置部分。配置,然后
- Determine that you didn't need them in your root application, or if you do
- 确定您在根应用程序中不需要它们,或者如果您需要它们。
- Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)
- 将父应用程序升级到ASP。NET 4.0(因此它可以访问根web。配置的configSections)
#1
183
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:
…略低于 <配置> 。相反,您需要包装单独的web。要禁用继承的配置节。例如:
<!-- 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"
.
虽然 <清楚> 可能为一些配置的部分工作,有一些,而不是需要一个 <删除name = "…"> 指令,还有一些似乎不支持。在这些情况下,它可能是适当的设置inheritInChildApplications = " false "。
#2
58
It needs to go directly under the root <configuration>
node and you need to set a path like this:
它需要直接在根 <配置> 节点,您需要设置一个路径是这样的:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
A better way to handle configuration inheritance is to use a <clear/>
in the child config wherever you don't want to inherit. So if you didn't want to inherit the parent config's connection strings you would do something like this:
处理配置继承的更好方法是在不希望继承的地方在子配置中使用
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
#3
18
I put everything into:
我把一切都放在:
<location path="." inheritInChildApplications="false">
....
</location>
except: <configSections/>
, <connectionStrings/>
and <runtime/>
.
除了:
There are some cases when we don't want to inherit some secions from <configSections />
, but we can't put <section/>
tag into <location/>
, so we have to create a <secionGroup />
and put our unwanted sections into that group. Section groups can be later inserted into a location tag.
有些情况下,我们不希望继承
So we have to change this:
所以我们必须改变这一点:
<configSections>
<section name="unwantedSection" />
</configSections>
Into:
成:
<configSections>
<sectionGroup name="myNotInheritedSections">
<section name="unwantedSection" />
</sectionGroup>
</configSections>
<location path="." inheritInChildApplications="false">
<myNotInheritedSections>
<unwantedSection />
</myNotInheritedSections>
</location>
#4
7
We were getting an error related to this after a recent release of code to one of our development environments. We have an application that is a child of another application. This relationship has been working fine for YEARS until yesterday.
在最近向我们的一个开发环境发布代码之后,我们遇到了与此相关的错误。我们有一个应用程序是另一个应用程序的子应用程序。直到昨天,这种关系一直都很好。
The problem:
We were getting a yellow stack trace error due to duplicate keys being entered. This is because both the web.config for the child and parent applications had this key. But this existed for many years like this without change. Why all of sudden its an issue now?
问题是:由于输入了重复的键,我们得到了一个黄色的堆栈跟踪错误。这是因为这两个网站。子应用程序和父应用程序的配置具有此键。但这种情况已经持续了很多年,没有改变。为什么现在突然成了问题?
The solution:
The reason this was never a problem is because the keys AND values were always the same. Yesterday we updated our SQL connection strings to include the Application Name in the connection string. This made the string unique and all of sudden started to fail.
解决方案:这不是问题的原因是键和值总是相同的。昨天我们更新了SQL连接字符串,将应用程序名称包含在连接字符串中。这使得字符串变得唯一,并且突然开始失败。
Without doing any research on the exact reason for this, I have to assume that when the child application inherits the parents web.config values, it ignores identical key/value pairs.
没有做任何研究确切的原因,我不得不认为当孩子应用程序继承了父母。配置值,它忽略了相同的键/值对。
We were able to solve it by wrapping the connection string like this
我们可以通过像这样封装连接字符串来解决它
<location path="." inheritInChildApplications="false">
<connectionStrings>
<!-- Updated connection strings go here -->
</connectionStrings>
</location>
Edit: I forgot to mention that I added this in the PARENTS web.config. I didn't have to modify the child's web.config.
编辑:我忘了提到我添加这个父母web . config。我没有修改孩子的web . config。
Thanks for everyones help on this, saved our butts.
谢谢大家的帮助,救了我们的屁股。
#5
4
If (as I understand) you're trying to completely block inheritance in the web config of your child application, I suggest you to avoid using the tag in web.config. Instead create a new apppool and edit the applicationHost.config file (located in %WINDIR%\System32\inetsrv\Config and %WINDIR%\SysWOW64\inetsrv\config). You just have to find the entry for your apppool and add the attribute enableConfigurationOverride="false"
like in the following example:
如果(正如我所理解的)您试图完全阻止子应用程序的web配置中的继承,我建议您避免在web.config中使用标记。相反,创建一个新的apppool并编辑applicationHost。配置文件(位于%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>
This will avoid configuration inheritance in the applications served by MyAppPool.
这将避免在appmypool服务的应用程序中继承配置。
Matteo
马特奥
#6
2
This is microsoft's page on the location
tag: http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx
这是微软在地址标签上的页面:http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx。
It may be helpful to some folks.
有些人可能会有帮助。
#7
1
We're getting errors about duplicate configuration directives on the one of our apps. After investigation it looks like it's because of this issue.
我们错误的重复配置指令我们的应用程序之一。经调查看来,因为这个问题。
In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.
简而言之,我们的根网站是ASP。NET 3.5(即添加了特定库的2.0),我们有一个子应用程序,即ASP。NET 4.0。
web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.
网络。配置继承导致ASP。继承web的NET 4.0子应用程序。父ASP的配置文件。NET 3.5的应用程序。
However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains these config sections.
然而,ASP。NET 4.0应用程序的全局(或“根”)web。配置,它驻留在Microsoft.NET \ Framework \ C:\Windows\ v4.0.30319 \ config \ web。配置和C:\Windows\ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ web。配置(取决于您的位),已经包含了这些配置部分。
The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the node.
ASP。NET 4.0应用程序试图将根ASP合并在一起。NET 4.0 web。配置和父web。配置(一个ASP的配置。NET 3.5 app),并在节点中运行。
The only solution I've been able to find is to remove the config sections from the parent web.config, and then either
我能找到的唯一解决方案是从父web中删除配置部分。配置,然后
- Determine that you didn't need them in your root application, or if you do
- 确定您在根应用程序中不需要它们,或者如果您需要它们。
- Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)
- 将父应用程序升级到ASP。NET 4.0(因此它可以访问根web。配置的configSections)