【问题标题】:Issues with Web.configWeb.config 的问题
【发布时间】:2014-11-18 10:03:03
【问题描述】:

我正在尝试使用 Web 部署将 MVC 应用程序部署到 EC2 实例,并且在我尝试运行该应用程序之前一切正常。我收到以下错误:

解析器错误消息:为 entityFramework 创建配置节处理程序时出错:在应用程序配置中多次指定 DbContext 类型“Project.Modules.AppDbContext, Project”的配置。每个上下文只能配置一次。

我查看了所有我能找到的相关问题(error There is a duplicate 'entityFramework' section definedThere is a duplicate 'entityFramework' section defined - EntityFramework6 upgradeThe type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exceptionThe provider for invariant name System.Data.SqlClient is specified multiple times)。它是一个 MVC 应用程序,因此有多个 Web.config 文件,但它抱怨的 EF 部分在这两个地方都不存在。以下是我的配置文件的相关部分:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
--------more config settings here---------
<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="Data Source=MYIP;Initial Catalog=db;Persist Security Info=True;User ID=user;Password=password" />
    </parameters>
  </defaultConnectionFactory>
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

我听说它应该在 6.1.0 中解决许多其他问题。如果我从 configSection 中删除该条目,它会给我另一个关于它如何找不到正确资源的错误。可能值得注意的另一件事是,如果我部署并取消选中“执行代码优先迁移”,它只会超时,而不是给我上述错误。

【问题讨论】:

    标签: c# asp.net-mvc entity-framework web-config asp.net-mvc-5


    【解决方案1】:

    在应用虚拟目录的根文件夹或父文件夹中检查 web.config。由于 web.config 继承而发生重复部分错误。

    wwwroot
       |-- web.config       <-- ensure this doesn't have any connection strings
       |-- your app
            |-- web.config  <-- inherites wwwroot\web.config's settings
    

    【讨论】:

      【解决方案2】:

      正如 vcsjones 在他们的回答中所说的 here 问题出在您的parent directory 中。即使您指定了一个,.config file 中也已经存在一个。

      【讨论】:

      • 我认为它与此类似......但看起来问题在于站点/应用程序关系。我有我的站点“项目”,但我还在该站点中创建了一个名为“项目”的应用程序,它创建了一个循环关系,我认为这会导致我的很多问题。有没有更好的方法来做到这一点?
      猜你喜欢
      • 2011-07-22
      • 2014-05-24
      • 2016-08-11
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      相关资源
      最近更新 更多