Introduction
Previous parts of this series:
Definition
ASP.NET Core is a cross-platform and open-source framework. ASP.NET Core supports Windows, Mac or Linux operating systems. It is used to develop modern, cloud-based and high-performance web applications.
Configuration Source
There are times when an application gets configuration settings from various sources such as a web config file, app config and so on. We can use configuration source for this purpose to configure various sources.
We implement ASP.NET Core application configurations based on the key-value pairs by configuration providers. Configuration providers read configurations data into key-value pairs from variety of configuration sources. There are different types of configuration sources are available, such as Azure Key Vault, Directory Files, App configurations, environment variables, and settings files.
The Web.config file is the common method of storing configuration settings in ASP.NET. In ASP.NET Core, we can create configuration settings in different ways and one of them is using the “appsettings.json”, that is the default configuration source in .NET Core. Configuration settings contain key values pairs.
Go to “appsettings.json” and we can see some default settings like database connection string.

Read Configuration Information
We can read the configuration information using IConfiguration services. IConfiguration is an interface defined in the “Microsoft.Extensions.Configuration” namespace. The IConfiguration interface looks like below.
In app settings, we have added the key as “Message” and gave the corresponding value as “Welcome To .Net Core”. We can read the configuration settings using the IConfiguration.
Here are the steps that explain how to read the configuration settings.
Go to the “Startup.cs” and create the constructor.
Declare the private variable as “_config”and assign the “config” variable to the private variable “_config” using constructor that is called dependency injection. We will see in detail about dependency injection in later articles. We can find the sample code for accessing the configuration settings.
- namespace WebApplication15
- {
- public class Startup
- {
- private IConfiguration _config;
- public Startup(IConfiguration config)
- {
- _config = config;
- }
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddSingleton<IMessages, Message>();
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.Run(async (context) =>
- {
- await context.Response.WriteAsync(_config["Message"]);
- });
- }
- }
- }



aziz bouhejbaPosted Nov 25, 2019, 11:26 AM
I don't get this, if I want to publish my app in custom environments.. what do I have to do.. Let's say I need a new custom environment "QA" for example and I want to use appsettings.qa.json when my app is deployed to IIS
DeepanPosted Nov 24, 2019, 1:46 AM
Good information
Chittaranjan SwainPosted Oct 19, 2019, 3:03 AM
Nice article, thanks for sharing....
Pankajkumar PatelPosted Oct 17, 2019, 11:02 PM
Nice article