Asp.net 使用inheritInChildApplications避免子web应用程序中的web.config继承
我想补充一点Asp.net 使用inheritInChildApplications避免子web应用程序中的web.config继承,asp.net,configuration,iis-7,web-config,Asp.net,Configuration,Iis 7,Web Config,我想补充一点 <location inheritInChildApplications="false"> My child web应用程序在IIS中设置为应用程序,并从父级的web.config继承,这会导致问题 我应该把行李放在哪里 <location inheritInChildApplications="false"> 因此,它会忽略所有的web.config设置?它需要直接进入根节点下,您需要设置如下路径: <?xml version="1.0"?&
<location inheritInChildApplications="false">
My child web应用程序在IIS中设置为应用程序,并从父级的web.config
继承,这会导致问题
我应该把行李放在哪里
<location inheritInChildApplications="false">
因此,它会忽略所有的web.config设置?它需要直接进入根
节点下,您需要设置如下路径:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
处理配置继承的更好方法是在不希望继承的子配置中使用
。因此,如果不想继承父配置的连接字符串,可以执行以下操作:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
正如前面提到的回答的评论者所说,您不能简单地添加行
<location path="." inheritInChildApplications="false">
…就在
下面。相反,您需要包装要禁用继承的各个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>
虽然
可能适用于某些配置部分,但有些部分需要
指令,还有一些似乎不支持。在这些情况下,设置inheritinchildaplications=“false”
可能是合适的,这是microsoft在位置上的页面
标记:
这可能对某些人有所帮助。我们的一个应用程序上出现了关于重复配置指令的错误。 经过调查,看起来是因为 简而言之,我们的根网站是ASP.NET3.5(它是2.0,添加了特定的库),我们有一个子应用程序是ASP.NET4.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)合并在一起,并在节点中重复运行 我能找到的唯一解决方案是从父web.config中删除配置部分,然后
在最近向我们的一个开发环境发布代码之后,我们遇到了一个与此相关的错误。我们有一个应用程序是另一个应用程序的子应用程序。多年来,这种关系一直运作良好,直到昨天 问题:
由于输入了重复的密钥,我们收到了黄色堆栈跟踪错误。这是因为子应用程序和父应用程序的web.config都有此键。但这种情况已经存在多年,没有改变。为什么现在突然成了问题 解决方案:
这从来都不是问题的原因是因为键和值总是相同的。昨天,我们更新了SQL连接字符串,将应用程序名称包含在连接字符串中。这使得字符串独一无二,并且突然开始失败 在不研究确切原因的情况下,我不得不假设当子应用程序继承父web.config值时,它会忽略相同的键/值对 我们可以通过如下方式包装连接字符串来解决此问题
<location path="." inheritInChildApplications="false">
<connectionStrings>
<!-- Updated connection strings go here -->
</connectionStrings>
</location>
编辑:我忘了提到我在PARENTS web.config中添加了这个。我不必修改孩子的web.config
谢谢大家在这方面的帮助,省去了我们的麻烦。如果(据我所知)您试图完全阻止子应用程序的web配置中的继承,我建议您避免使用web.config中的标记。
而是创建一个新的apppool并编辑applicationHost.config文件(位于%WINDIR%\System32\inetsrv\config和%WINDIR%\SysWOW64\inetsrv\config中)。
您只需找到应用程序池的条目并添加属性enableConfigurationOverride=“false”
,如以下示例所示:
<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
<processModel identityType="NetworkService" />
</add>
这将避免MyAppPool服务的应用程序中的配置继承
Matteo我把一切都投入到:
<location path="." inheritInChildApplications="false">
....
</location>
....
除了:
、
和
有些情况下,我们不想从
继承一些secion,但我们不能将
标记放入
,因此我们必须创建一个
并将不需要的部分放入该组。以后可以将横断面编组插入到位置标记中
因此,我们必须改变这一点:
<configSections>
<section name="unwantedSection" />
</configSections>
进入:
我在我的父web.config文件中遇到了一个错误“无法读取配置节'configSections',因为它缺少节声明”。您可以发布配置文件中的元素吗?我也会检查我的编辑,看看是否是一个更好的方法,你正在尝试做什么。它不工作,当你把它的权利下。你可以包装节点,但不能像这样把它放在根目录下。如果你把它放在第二个节点下,你会得到“inheritInChildApplications属性未声明”。因此,在web.config中,它不是该级别的有效属性。那么你怎么能说这是有效的呢?-1:我还可以确认,使用上面显示的location元素是无效的。这个链接已经失效了。试试这个:是pos吗