FeaturedIT topics

How to use configuration providers in ASP.Net Core

Microsoft’s ASP.Net Core is an open-source, cross-platform, lean, and modular framework for building high-performance, scalable web applications. Configuration data in ASP.Net Core is stored as key-value pairs, and can be organized in a multi-level manner. In this article, we will create a new ASP.Net Core project and then use this project to examine how we can work with configuration data in an ASP.Net Core application.

Create a new ASP.Net Core project

To create a new ASP.Net Core project, follow the steps outlined below. Note that this post assumes that you have Visual Studio 2017 installed in your system.

  1. Open Visual Studio 2017 IDE.
  2. Click on File > New > Project.
  3. Select “ASP.Net Core Web Application (.Net Core)” from the list of the templates.
  4. Specify a name for the project.
  5. Click OK.
  6. Select “API” in the “New .Net Core Web Application…” window.
  7. Select the version of ASP.Net Core you would like to use from the drop-down list at the top.
  8. Uncheck the “Enable Docker Support” and “Configure for HTTPS” options. 
  9. Select “No Authentication” as we won’t be using it either.
  10. Click OK.

A new ASP.Net Core project will be created. Note that when a new ASP.Net Core project is created, two files — namely, appsettings.json and appsettings.Development.json — will be configured. Another point to note here is that beginning with ASP.Net Core 2.0, configuration data can now be configured in Program.cs. You are no longer constrained to specify configuration data only in the Startup.cs file. Here is how your Program.cs file will look in ASP.Net Core 2.1:

Related Articles

Back to top button