[英]ASP.Net Core - Configuration Manager doesn't load data from Web.config
我正在将应用程序从.Net Framework 移植到.Net Core,并尝试使用System.Configuration.ConfigurationManager
package 中的ConfigurationManager
从Web.config
获取连接字符串。 问题是它只包含machine.config
的默认连接字符串。 我知道 ASP.Net Core 使用appsettings.json
和IConfiguration
作为管理配置的默认方式,但据我了解System.Configuration.ConfigurationManager
package 被添加以简化迁移。 那么这是使用ConfigurationManager
从Web.config
而不是全局machine.config
获取数据的正确方法吗?
Web.config内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="My" connectionString="sample data" />
</connectionStrings>
</configuration>
看起来该文件必须命名为App.config
,即使它是 web 应用程序。 将Web.config
重命名为App.config
后,它可以正确读取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.