【问题标题】:Why i cannot run my MVC5 app, error from web.config file?为什么我无法运行我的 MVC5 应用程序,来自 web.config 文件的错误?
【发布时间】:2018-05-02 16:59:05
【问题描述】:

在我的 MVC 应用程序中,WebUI 项目的 web.config 文件已使用以下 connectionStrings 标记进行了修改

    <connectionStrings>
    <add name="EFDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=SportsStore;Integrated Security=True"  providerName="System.Data.SqlClient"/>
  </connectionStrings>

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

当按 F5 时,它会显示以下链接中显示的以下错误页面,谁能告诉我为什么以及如何解决这个问题?

注意:如果&lt;connectionStrings&gt;...&lt;/connectionStrings&gt; 中没有连接字符串,它可以工作。但为什么是错误?

https://1drv.ms/a/s!AnpqTBe4ZZ2hbO7cMNILg4PTeBk

【问题讨论】:

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


    【解决方案1】:

    正如错误消息所说。您的配置文件中只能有 1 个 configSections 元素。此外,它必须是配置文件中&lt;configuration&gt;first子元素。

    <configuration>
        <configSections>    
            <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </configSections>
    
        <connectionStrings>
            <add name="EFDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=SportsStore;Integrated Security=True"  providerName="System.Data.SqlClient"/>
        </connectionStrings>
    </configuration>
    

    来自MSDN

    备注

    如果此元素在配置文件中,则它必须是&lt;configuration&gt; 元素的第一个子元素。

    参考资料:

    【讨论】:

    • thanks 解决了我的问题,所以 web.config 中的第一行必须是 有没有办法知道 web.config 文件中其他元素的顺序......?跨度>
    • @Mr.Tib - 我已将相关文档的链接添加到我的答案中。
    • 感谢您提供的文章链接:)
    【解决方案2】:
      <configSections>    
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
    
            <connectionStrings>
        <add name="EFDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=SportsStore;Integrated Security=True"  providerName="System.Data.SqlClient"/>
      </connectionStrings>
    

    &lt;confogSections&gt;交换&lt;connectiornStrings&gt;

    错误说你只能有一个 configSection 属性,而且它必须在配置文件中的第一个。

    【讨论】:

    • 我很难理解您所写的内容,但我相信您尝试将 进行交换,NightOwl888 对此进行了很好的解释
    • 是的,交换,这是一个错字。
    猜你喜欢
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 2012-12-19
    • 1970-01-01
    • 2012-09-27
    • 2018-06-23
    相关资源
    最近更新 更多