ASP.NET Core Configuration & Logging 1 — Questions and Answers
Question 1: Which file is the primary configuration source in an ASP.NET Core application?
- appsettings.json (Correct answer)
- web.config
- config.json
- settings.json
Correct answer: appsettings.json
appsettings.json is the default configuration file read by the ASP.NET Core host, with environment-specific overrides supported.
Question 2: What is the correct order for configuration providers in the default ASP.NET Core host?
- appsettings.json → appsettings.{env}.json → environment variables → command-line (Correct answer)
- command-line → environment variables → appsettings.json
- Environment variables first, then all JSON files
- All sources have equal priority
Correct answer: appsettings.json → appsettings.{env}.json → environment variables → command-line
Later providers override earlier ones, so environment variables and command-line arguments override JSON file values by default.
Question 3: How do you access a nested configuration value 'Database:ConnectionString' in ASP.NET Core?
- configuration["Database:ConnectionString"] (Correct answer)
- configuration.Get("Database.ConnectionString")
- configuration.Database.ConnectionString
- config["Database"]["ConnectionString"]
Correct answer: configuration["Database:ConnectionString"]
Hierarchical configuration keys use colon (:) as the separator when accessed via the IConfiguration indexer.
Question 4: What is the purpose of the IOptions<T> interface in ASP.NET Core?
- To inject strongly typed configuration settings bound to a class (Correct answer)
- To define optional dependencies in DI
- To configure middleware options at startup
- To access environment-specific settings only
Correct answer: To inject strongly typed configuration settings bound to a class
IOptions<T> provides a bound, typed settings object injected into services, configured via services.Configure<T>().
Question 5: Which method binds a configuration section to a C# class in ASP.NET Core?
- services.Configure<TOptions>(configuration.GetSection("Section")) (Correct answer)
- configuration.Bind<TOptions>("Section")
- services.BindOptions<TOptions>()
- IOptions.Map<TOptions>()
Correct answer: services.Configure<TOptions>(configuration.GetSection("Section"))
services.Configure<T>() with GetSection() registers the options class and binds configuration values to its properties.
Question 6: Which configuration provider lets you store sensitive data outside the project during development?
- Secret Manager (User Secrets) (Correct answer)
- Environment variables only
- Azure Key Vault only
- Encrypted appsettings.json
Correct answer: Secret Manager (User Secrets)
The Secret Manager tool stores secrets in a per-user profile folder outside the project tree, preventing accidental commits.
Which file is the primary configuration source in an ASP.NET Core application?