简体   繁体   中英

ASP.Net Core - Configuration Manager doesn't load data from Web.config

I'm porting an app from.Net Framework to.Net Core and try to use ConfigurationManager from System.Configuration.ConfigurationManager package to get a connection string from Web.config . The problem is that it only contains default connection string from machine.config . I know that ASP.Net Core use appsettings.json with IConfiguration as a default way to manage configuration but as I understand System.Configuration.ConfigurationManager package was added to simplify the migration. So that's the right way to use ConfigurationManager to get the data from Web.config instead of global machine.config ?

Web.config content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="My" connectionString="sample data" />
  </connectionStrings>
</configuration>

Looks like the file must be named App.config , even if it's web app. After renaming Web.config to App.config it's read properly

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