There are a bunch of contradictory statements about web.config and .NET Core.
Additionally, I've just deployed a mostly-fresh-out-of-the-box .NET Core app to Azure. In the repository, there's no web.config but when I explore the deployed code in Kudu, there IS a web.config file?
In order to set up the ASP.NET Core Module correctly, the web. config file must be present at the content root path (typically the app base path) of the deployed app.
web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.
Yes, you will be able to run an ASP.NET application without a WEB. CONFIG file in its root folder. If the application doesn't find a WEB. CONFIG file in its root folder, then it will take MACHINE.
config is parsed at runtime, so if you edit the web. config file, the web application will automatically load the changes in the config file. Â app. config is parsed at compile time, so if you edit the app.
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.
Read a few web.config
examples from Google and you should notice that,
<system.web>
).<system.webServer>
).So migrating to ASP.NET Core only make the first obsolete, and you should only say goodbye to that piece of knowledge.
If you host your web app on IIS, then web.config
is still needed, as you need initial settings there to configure ASP.NET Core module for IIS/IIS Express (dotnet publish
generates such a file if you don't have your own).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With