ASP.NET Core Interview Question #244
How would you handle configuration and secrets across multiple environments?
Senior ASP.NET Core Real-World Scenarios Senior Advanced
Quick Interview Answer
Keep ordinary non-secret defaults in configuration files and override environment-specific values through deployment configuration. Store passwords, API keys, certificates, and signing credentials in a protected secret store or platform secret mechanism rather than source control.
Detailed Explanation
Keep ordinary non-secret defaults in configuration files and override environment-specific values through deployment configuration. Store passwords, API keys, certificates, and signing credentials in a protected secret store or platform secret mechanism rather than source control.
Use strongly typed options and validate critical configuration during startup so invalid deployments fail early. Keep configuration names consistent across environments while values differ.
Do not log secret values during startup diagnostics, and design a rotation process for credentials that must change without major code changes.
Code Example
builder.Services
.AddOptions<PaymentOptions>()
.Bind(builder.Configuration.GetSection("Payments"))
.ValidateDataAnnotations()
.ValidateOnStart();