Showing posts with label ConfigurationBuilder. Show all posts
Showing posts with label ConfigurationBuilder. Show all posts

Thursday, April 9, 2020

Access configuration settings from custom configuration files

In the previous post we saw on how to read configuration settings from the appsettings.json file. While this holds good for most of the cases, there might be situations where we will need our custom configuration file, when we use our own configuration file, we need to specify the file in the Startup and add the file to the ConfigurationBuilder.

In the below case we have a custom configuration file mysettings.json, and we will read the configuration settings from our config file.

Friday, February 22, 2019

Adding Configuration to Asp.Net Core

Configuration is another important aspect of any Application, in this post we shall see on how to add a configuration file and read the key/value pairs from the config file in the application. In traditional Asp.Net and MVC applications we had a default web.config file where we can add the config entries and use them in the application. Asp.Net core is different, here we use a JSON file for the configurations. In this post we will add a configuration file appsettings.json and read the config entries from the file at Startup.

Let us use the basic Hello World application and modify it slightly to add the configurations. First add a new JSON file to the application, name it appsettings.json. Let us add a config entry to the file as follows.