⚙️ Introduction
In ASP.NET Core development, configuration plays a very important role. Instead of hardcoding values in code, developers use a configuration system to manage settings like database connections, logging levels, API keys, and environment-specific values. The most commonly used configuration file is appsettings.json, and the main way to read these settings in your application is through IConfiguration. In this article, we will explain in simple terms how to use appsettings.json and IConfiguration with examples. All content is written to be SEO and GEO-friendly, so developers worldwide can easily understand.
📄 What is appsettings.json?
The appsettings.json file is a JSON (JavaScript Object Notation) file used in ASP.NET Core applications to store configuration data. It acts like a central place where you keep application settings that may change depending on the environment.
Key Features
Human-readable JSON format.
Hierarchical structure (supports nested sections).
Supports multiple environment files (e.g., appsettings.Development.json, appsettings.Production.json).
Automatically loaded by ASP.NET Core at startup.
Example of appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=mydb;User Id=sa;Password=YourPassword;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning"
}
},
"AppSettings": {
"ApplicationName": "My ASP.NET Core App",
"Version": "1.0"
}
}
In this example
ConnectionStringsstore's database details.Loggingdefines how much log detail should be shown.AppSettingsstores custom application values.
🛠️ What is IConfiguration?
The IConfiguration interface in ASP.NET Core is used to read values from appsettings.json (and other sources like environment variables, command-line arguments, or secrets). It provides a simple way to access settings by key.
Key Features
Reads data from appsettings.json, environment variables, and more.
Supports hierarchical keys (e.g.,
Logging:LogLevel:Default).Allows strongly typed configuration with classes.
Example of using IConfiguration
public class HomeController : Controller
{
private readonly IConfiguration _configuration;
public HomeController(IConfiguration configuration)
{
_configuration = configuration;
}
public IActionResult Index()
{
var appName = _configuration["AppSettings:ApplicationName"];
var version = _configuration["AppSettings:Version"];
ViewData["Message"] = $"{appName} - Version {version}";
return View();
}
}

Join the conversation! Your thoughts help the community grow.