How to Read Values From appsettings.json In ASP.Net Core

  • Oct 24, 2021
  • 2
  • 973

How to Read values from appsettings.json in ASP.Net Core?

Answers (2)
Answer Accepted

We will use the "appsettings.json" file to store the configurations and also read those configurations using JsonConfigurationProvider provided by Microsoft. 

Sample appsettings.json file:

"WebsiteSettings": {
    "Name": "Techieclues - A developer community website",
    "Header": {
      "MainBannerTitle": "Articles, Blogs and Q&As",
      "HomePageSize": 25,
      "RightSideMenu": true


The class name and properties should match with the appsetting.json section.

public class WebsiteSettings
	public string Name { get; set; }
	public HeaderSettings Header { get; set; }
public class HeaderSettings
	public string MainBannerTitle { get; set; }
	public int HomePageSize { get; set; }
	public bool RightSideMenu { get; set; }

Using Bind method of IConfiguration, we can easily get the values from the appsettings.json file.

var websiteSettings = new WebsiteSettings();
// Retrieving and binding WebsiteSettings section using IConfiguration.  
configuration.Bind("WebsiteSettings", websiteSettings);
// Serialize object
return Content(JsonConvert.SerializeObject(websiteSettings));

If you want to more details, please see our article, Getting Values From appsettings.json File In ASP.Net Core.

The much-required room for personalization is provided by the custom items. It might be difficult to integrate organizational data into stand objects as every company has its own unique needs. In addition, "customization" is one of Salesforce's most prominent slogans as it describes the platform's ability to adapt to each client's unique needs. All the way from the individualized part to the unique user interface and even the unique items. 

Submit your answer