首页 > 解决方案 > Can't read connection string from web.config

问题描述

I have the following in my web.config located at the root of my project:

<configuration>
  <connectionStrings>
    <clear />  
    <add name="Default" providerName="System.Data.SqlClient" connectionString="Server=tcp:whoops;Encrypt=True;TrustServerCertificate=False;Connection Timeout=3000;" />
  </connectionStrings>
  <appSettings>
    <add key="ConnectionString" value="test"/>
  </appSettings>
  ....

I read from Startup.cs (this is an asp.net core web app):

 string connection = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

However when I break on this, ConfigurationManager.ConnectionStrings and ConfigurationManager.AppSettings are empty (well, the first has some default connection string that is not the one in web.config).

What's going on here?

标签: c#asp.net-coreweb-config

解决方案



推荐阅读