In this article I will explain with an example, how to use ConfigurationManager.AppSettings in .Net Core and ASP.Net MVC Core.
Microsoft has replaced ConfigurationManager.AppSettings class of System.Configuration namespace with IConfiguration interface in .Net Core 2.0.
What is IConfiguration
The IConfiguration is an interface for .Net Core 2.0.
The IConfiguration interface need to be injected as dependency in the Controller and then later used throughout the Controller.
The IConfiguration interface is used to read Settings and Connection Strings from AppSettings.json file.
You will need to import the following namespace.
Adding the AppSettings.json file
In order to add AppSettings.json file, right click on the Project in Solution Explorer. Then click Add, then New Item and then choose App Settings File option (shown below) and click Add button.
Once the File is created, it will have a DefaultConnection, below that a new AppSettings entry is added.
"AppName": "Test App",
Reading AppSettings from AppSettings.json file using IConfiguration interface
In the below example, the IConfiguration is injected in the Controller and assigned to the private property Configuration.
Then inside the Controller, the AppSettings are read from the AppSettings.json file using the GetSection function.
public class HomeController : Controller
private IConfiguration Configuration;
public HomeController(IConfiguration _configuration)
Configuration = _configuration;
public IActionResult Index()
string appName = this.Configuration.GetSection("AppSettings")["AppName"];
string site = this.Configuration.GetSection("AppSettings")["Site"];