简体   繁体   中英

Issues with Web.config

I am trying to deploy an MVC app to an EC2 instance using Web Deploy, and everything is working until I try to run the application. I get the following error:

Parser Error Message: An error occurred creating the configuration section handler for entityFramework: Configuration for DbContext type 'Project.Modules.AppDbContext, Project' is specified multiple times in the application configuration. Each context can only be configured once.

I have looked all of the related issues I could find ( error There is a duplicate 'entityFramework' section defined , There is a duplicate 'entityFramework' section defined - EntityFramework6 upgrade , The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception , The provider for invariant name System.Data.SqlClient is specified multiple times ). It is an MVC app so there are multiple Web.config files, but the EF section it is complaining about doesn't exist in both places. Here are the relevant portions of my config file:

<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>

I have heard anything from it should be resolved in 6.1.0 to many other things. If I remove the entry from the configSection it gives me another error about how it can't find the right resources. The only other thing that might be worth noting is that if I deploy and un-check 'Execute Code First Migrations' it just times out instead of giving me the above error.

Check web.config in root or parent folders of your app's virtual directory. The duplicate section error happens due to web.config inheritance.

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

正如他们的回答vcsjones状态这里的问题是在你的parent directory 。即使你指定的一个,已经有一个在.config file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM