[英]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
.我正在将应用程序从.Net Framework 移植到.Net Core,并尝试使用
System.Configuration.ConfigurationManager
package 中的ConfigurationManager
从Web.config
获取连接字符串。 The problem is that it only contains default connection string from machine.config
.问题是它只包含
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.我知道 ASP.Net Core 使用
appsettings.json
和IConfiguration
作为管理配置的默认方式,但据我了解System.Configuration.ConfigurationManager
package 被添加以简化迁移。 So that's the right way to use ConfigurationManager
to get the data from Web.config
instead of global machine.config
?那么这是使用
ConfigurationManager
从Web.config
而不是全局machine.config
获取数据的正确方法吗?
Web.config content: Web.config内容:
<?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.看起来该文件必须命名为
App.config
,即使它是 web 应用程序。 After renaming Web.config
to App.config
it's read properly将
Web.config
重命名为App.config
后,它可以正确读取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.