简体   繁体   English

ASP.Net Core - 配置管理器不从 Web.config 加载数据

[英]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 中的ConfigurationManagerWeb.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.jsonIConfiguration作为管理配置的默认方式,但据我了解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 ?那么这是使用ConfigurationManagerWeb.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 properlyWeb.config重命名为App.config后,它可以正确读取

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM