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

前端之家收集整理的这篇文章主要介绍了c# – 在web.config中放置连接字符串的位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的web.config看起来像这样:
  1. <configuration>
  2.  
  3. <configSections>
  4. <!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  5. <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  6. </configSections>
  7. <appSettings>
  8. <add key="webpages:Version" value="3.0.0.0" />
  9. <add key="webpages:Enabled" value="false" />
  10. <add key="ClientValidationEnabled" value="true" />
  11. <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  12. </appSettings>
  13. <system.web>
  14. <compilation debug="true" targetFramework="4.5.1" />
  15. <httpRuntime targetFramework="4.5.1" />
  16. </system.web>
  17. <runtime>

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

解决方法

只需将其置于< configuration>内即可.在< / configSections>之后F.E.
  1. <configuration>
  2. <configSections>
  3. <!-- For more information on Entity Framework configuration,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  4. </configSections>
  5. <connectionStrings>
  6. <add name="DefaultConnection" connectionString="blablabla" providerName="System.Data.sqlClient" />
  7. </connectionStrings>
  8. <appSettings>
  9. <add key="webpages:Version" value="3.0.0.0" />
  10. <add key="webpages:Enabled" value="false" />
  11. <add key="ClientValidationEnabled" value="true" />
  12. <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  13. </appSettings>
  14. <system.web>
  15. <compilation debug="true" targetFramework="4.5.1" />
  16. <httpRuntime targetFramework="4.5.1" />
  17. </system.web>
  18. ...

猜你在找的C#相关文章