ASP.NET Core configuration merges appsettings.json, environment-specific files, environment variables, and command-line args into one key-value system—accessed via IConfiguration or strongly typed options.
appsettings.json example
{
"ConnectionStrings": {
"Default": "Server=.;Database=AppDb;Trusted_Connection=true"
},
"Logging": { "LogLevel": { "Default": "Information" } }
}
Reading configuration
var conn = builder.Configuration.GetConnectionString("Default");
builder.Services.Configure<SmtpOptions>(
builder.Configuration.GetSection("Smtp"));
Environment overrides
appsettings.Development.json overrides base settings when ASPNETCORE_ENVIRONMENT=Development. Production secrets belong in environment variables or Azure Key Vault—not committed JSON.
Important interview questions and answers
- Q: Where store production secrets?
A: Environment variables, secret managers, Key Vault—never plain text in git. - Q: IOptions vs IConfiguration?
A: IOptions binds a section to a typed POCO with validation; IConfiguration is raw key lookup.
Self-check
- Which file typically holds connection strings?
- How does Development settings override Production defaults?