简体   繁体   English

.NET 标准类库中的 System.Web

[英]System.Web in .NET Standard Class Library

I am trying to port our existing .NET 4.6.1 class library to .NET Standard 2.1 .我正在尝试将我们现有的.NET 4.6.1类库移植到.NET Standard 2.1 Most of the dependencies are resolved.大多数依赖项都已解决。 However I am unsure what to do with the System.Web.Configuration .但是我不确定如何处理System.Web.Configuration Our current code has something like this:我们当前的代码是这样的:

config = WebConfigurationManager.OpenWebConfiguration("~/");
  • How to include the dependency with System.Web.Configuration to my project?如何将 System.Web.Configuration 依赖项包含到我的项目中?
  • How to change the code to remove this dependency?如何更改代码以删除此依赖项?

System.Web.Configuration is not part of .netstandard / .netcore. System.Web.Configuration 不是 .netstandard / .netcore 的一部分。 For a web application, the configuration is not done on a web.config anymore, but on an appsettings.json (with possibilities to have environment specific configurations).对于 Web 应用程序,配置不再在 web.config 上完成,而是在 appsettings.json 上完成(可能具有特定于环境的配置)。

Instead of using System.Web.Configuration, you should use Microsoft.Extensions.Configuration.您应该使用 Microsoft.Extensions.Configuration 而不是使用 System.Web.Configuration。 The IConfiguration interface represents by default the configuration of your website and can be injected into your services. IConfiguration 接口默认代表您网站的配置,可以注入到您的服务中。

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

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