【问题标题】:Duplicate section error even after using <remove> tag in web.config for IIS即使在 IIS 的 web.config 中使用 <remove> 标记后,也会出现重复部分错误
【发布时间】:2016-09-09 17:10:25
【问题描述】:

我有一个站点在另一个站点的子目录中运行。它们在不同的应用程序池中运行。这两个站点运行不同版本的实体框架。所以在子目录的 web.config 中我有:

<remove name="entityFramework"/>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

但即使使用&lt;remove&gt; 标签,我仍然会收到此错误:

Section or group name 'entityFramework' is already defined. Updates to this may only occur at the configuration level where it is defined.

我还在父 web.config 中尽可能放置了 &lt;location&gt; 标签:

<location path="." inheritInChildApplications="false">

&lt;location&gt; 标记出现在父 web.config 的 &lt;entityFramework&gt; 部分周围。

我已将enableConfigurationOverride="false" 放置在 IIS 的 applicationHost.config 文件中(System32 和 SysWOW64 中的文件)。

如何防止子目录中的网站看到父entityFramework标签?

编辑

IIS 版本:7.5.7600.16385

来自父 web.config:

<configSections>
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

l

  <location path="." inheritInChildApplications="false">
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
  </location>

来自子 web.config:

  <configSections>
    <remove name="entityFramework"/>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />    
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

l

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

编辑 2

关于使用&lt;clear/&gt;:这会导致一系列关于缺少部分声明的错误。如果我添加回约 100 行的部分声明,我会收到错误:An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. 即使我在 &lt;system.webServer&gt; 中使用 &lt;validation validateIntegratedModeConfiguration="false" /&gt;,错误仍然存​​在。

【问题讨论】:

  • IIS 版本是多少?你能准确地展示你所拥有的 - 配置部分下的部分定义和实际的 EF 部分。
  • @G.Stoynev 我已经用您要求的信息更新了问题。
  • 删除重复部分会怎样?您是否尝试解决指定程序集版本的此问题? dependentAssembly>
  • 您是否尝试将 添加到

标签: asp.net iis


【解决方案1】:

您能否确认您是否尝试了clear 而不是remove,问题仍然存在吗?

 <configSections>
    <clear/>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />    
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

您可能会阅读更多here

希望对你有帮助

【讨论】:

  • 这个错误集成托管管道与IIS有关,更改您的IIS设置,通常更改ApplicationPool设置会解决问题
  • 我确实有一个复制品,&lt;clear /&gt; is not helping. There are many references to a Microsoft Connect (now 404) to a post from Microsoft explaining why '` 和 &lt;remove /&gt; 不打算与 &lt;configSections&gt; 一起使用。
【解决方案2】:

您说您使用但在您发布的父 web.config 中,路径 =“。”不见了。您将需要它来阻止继承。

【讨论】:

  • 抱歉,这是一个粘贴错误。我已经验证了 path="."存在并且错误仍然存​​在。我也更新了问题以反映这一点。
【解决方案3】:

你试过这个删除属性吗

<system.web>
  <compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>

http://weblogs.asp.net/srkirkland/common-web-config-transformations-with-visual-studio-2010

Example 2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 2019-06-19
    • 2013-05-14
    相关资源
    最近更新 更多