There are a bunch of contradictory statements about web.config and .NET Core.
In a .NET Framework Web application, web.config is used for two purposes:
To store configuration for the web application.
To store configuration for the IIS that hosts the application (system.webServer
element).
In a .NET Core Web application, you have at least two choices for storing application configuration:
Use a .NET Core Configuration Provider, often with a json configuration file.
Use the System.Configuration.ConfigurationManager NuGet package with recent versions of .NET Core (2.0+ I think). One advantage of using System.Configuration.ConfigurationManager
is that it can be used in .NET Standard 2.0 libraries that are compatible with both .NET Core and .NET Framework.
If you choose to use System.Configuration.ConfigurationManager
in a .NET Core web application, you need to add an app.config
(not web.config
) file to your Visual Studio project. When you build this project it will be copied to the output directory and renamed as appName.dll.config
.
If you are hosting your .NET Core web application in IIS, you can still need a web.config
file with configuration for IIS (system.webServer
element). I.e. your application may need both app.Config
and web.config
.
Personally I prefer to use System.Configuration.ConfigurationManager
and an app.config
XML configuration file, for several reasons including compatibility with .NET Framework, the fact that it's easy to comment out bits of XML, etc. YMMV of course.