首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >避免在使用inheritInChildApplications的子web应用程序中继承web.config

避免在使用inheritInChildApplications的子web应用程序中继承web.config
EN

Stack Overflow用户
提问于 2009-04-23 15:26:00
回答 5查看 199.5K关注 0票数 165

我正在尝试添加

代码语言:javascript
复制
<location inheritInChildApplications="false">

到我的父web应用程序的web.config,但它似乎不起作用。

我父母的web.config有:

代码语言:javascript
复制
<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

我到底应该把

代码语言:javascript
复制
<location inheritInChildApplications="false">

所以它会忽略所有的web.config设置?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-05-12 02:10:04

作为前面提到的答案的评论者,您不能简单地添加行...

代码语言:javascript
复制
<location path="." inheritInChildApplications="false">

<configuration>下面的...just。相反,您需要包装要禁用继承的单个web.config节。例如:

代码语言:javascript
复制
<!-- 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"可能是合适的。

票数 211
EN

Stack Overflow用户

发布于 2009-04-23 15:30:02

它需要直接转到根<configuration>节点下,您需要设置如下路径:

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>
    <location path="." inheritInChildApplications="false"> 
        <!-- Stuff that shouldn't be inherited goes in here -->
    </location>
</configuration>

处理配置继承的更好方法是在您不想继承的地方使用子配置中的<clear/>。因此,如果你不想继承父配置的连接字符串,你可以这样做:

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>
    <connectionStrings>
        <clear/>
        <!-- Child config's connection strings -->
    </connectionStrings>
</configuration>
票数 68
EN

Stack Overflow用户

发布于 2014-06-27 20:35:32

我把所有的东西都放在:

代码语言:javascript
复制
<location path="." inheritInChildApplications="false">
....
</location>

除了:<configSections/><connectionStrings/><runtime/>

在某些情况下,我们不想从<configSections />继承一些<section/>,但是我们不能将<location/>标记放入到<secionGroup />中,所以我们必须创建一个secions,并将不需要的部分放入该组中。以后可以将横断面组插入到位置标记中。

所以我们必须改变这一点:

代码语言:javascript
复制
<configSections>
  <section name="unwantedSection" />
</configSections>

进入:

代码语言:javascript
复制
<configSections>
  <sectionGroup name="myNotInheritedSections">
    <section name="unwantedSection" />
  </sectionGroup>
</configSections>

<location path="." inheritInChildApplications="false">
    <myNotInheritedSections>
        <unwantedSection />
    </myNotInheritedSections>
</location>
票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/782252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档