System.Web in .NET Standard Class Library

Viewed 4077

I am trying to port our existing .NET 4.6.1 class library to .NET Standard 2.1. Most of the dependencies are resolved. However I am unsure what to do with the 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?
  • How to change the code to remove this dependency?
1 Answers

System.Web.Configuration is not part of .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).

Instead of using System.Web.Configuration, you should use Microsoft.Extensions.Configuration. The IConfiguration interface represents by default the configuration of your website and can be injected into your services.

Related