home / software / tips and tricks / Web.config and ASP.Net Core?

Web.config and ASP.Net Core?

Updated:  10/08/2017 16:10 PM
Author:  Shiju Mathews

Status:    Resolved.


We are hearing a lot about "ASP.Net core we do not have web.config rather we have app.config file. In ASP.Net Core " . But the answer is 'yes' and 'no'.
As we see in the statement there is no "Web.config" in the solution. The solution is managed by a set of configuration files eg. Startup.cs, appsettings.json etc.

But on the other side when the code is deploying to IIS, you can see web.config, with a small code base.

All developers like us will immediately will ask a question, then how will be manage the application configuration values. To understand this we need to visit the structure of the project. For analytical purpose I have created a blank Visual studio 2017 solution and added an "ASP.NET Core" MVC project. Out of the box there is no web.config. But there is also a file called "appsettings.json".
Insider to understand the situation we need to start with another file called "Startup.cs" . First look at the constructor.



The method AddJsonFile is our point of interest. Here we are adding the root configuration file and the environment based configuration file to the configuration. alsoi keep in mind we are allowed to use other formats for configuration data like json (xml etc.)
Next take a look at the function ConfigureServices


Now we are adding the configuration to the services as a singleton method. Now we are all set to use the configuration values in the application.
Now we can access the configuration values from from 'appsettings.json' as follows.


Where the json File looks like



Tags: Web.config and ASP.Net Core?
Updated on: March 2024