Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 715
Random Avatar asked Mar 28 '26 17:03

Random


1 Answers

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

like image 140
Random Avatar answered Mar 30 '26 07:03

Random



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!