c# – 在web.config中放置连接字符串的位置

前端之家收集整理的这篇文章主要介绍了c# – 在web.config中放置连接字符串的位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的web.config看起来像这样:
<configuration>

  <configSections>
    <!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <runtime>

当我在< configuration>下面添加我的连接字符串时我得到一个错误,说只有一个< configSections>元素是允许的.我应该把我的连接字符串放在哪里?

解决方法

只需将其置于< configuration>内即可.在< / configSections>之后F.E.
<configuration>
    <configSections>
    <!-- For more information on Entity Framework configuration,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <connectionStrings>
        <add name="DefaultConnection" connectionString="blablabla" providerName="System.Data.sqlClient" />
    </connectionStrings>    
    <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.5.1" />
        <httpRuntime targetFramework="4.5.1" />
    </system.web>
    ...
原文链接:https://www.f2er.com/csharp/98407.html

猜你在找的C#相关文章