如何防止"configSections"的web.config文件继承?

DSh*_*per 14 c# asp.net visual-studio-2010 visual-studio

我在我的父Web应用程序配置文件中有以下内容

<configuration>
  <configSections>
    <sectionGroup name="testmodule">
      <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
    </sectionGroup>
  </configSections>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我想防止子子文件夹继承此配置部分应放在哪里 <location path="." inheritInChildApplications="false">,因为配置部分应该是配置文件的第一个子元素

Nar*_*man 10

在SO上已经回答了几次,但在我看来这是错误的.

文档很清楚(1)(2):

以下示例说明如何在配置文件中使用此属性,以指定子应用程序不应继承在网站根目录的location元素中定义的设置:

InheritInChildApplications属性仅适用于特定于位置的配置设置.

要回答你的问题,这应该足够了:

<configuration>
...
<sectionGroup name="testmodule">
    <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
...
<location path="." inheritInChildApplications="false">
    <testModule>
    ....
    </testModule>
</location>
Run Code Online (Sandbox Code Playgroud)

(1) - http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.inheritinchildapplications.aspx

(2) - http://msdn.microsoft.com/en-us/library/ms178692.aspx


DSh*_*per 6

目前似乎没有解决方案,应避免在web.config文件中使用冲突的节组.