Use the layered configuration system: appsettings files for defaults, environment specific files, then environment variables and a secret store on top, with later sources overriding earlier ones. Bind sections to strongly typed classes with the options pattern and validate them at startup. Keep secrets out of source control entirely, using user secrets in development and a vault such as Azure Key Vault in production, ideally reached through a managed identity.
Why interviewers ask this
Leaked connection strings in repositories remain a common cause of breaches, and misconfiguration is a common cause of outages. The interviewer wants to see that you understand configuration providers and precedence, use typed options rather than magic strings, and fail fast on invalid settings. Reaching secrets through a vault with a managed identity, rather than storing yet another secret to unlock the first, shows mature security habits.
How to structure your answer
- Explain configuration sources and precedence.
- Describe the options pattern and validation at startup.
- Cover secrets in development and in production.
- Mention reloading and the different options interfaces.
Example answer
ASP.NET Core builds configuration from layered sources: appsettings.json for defaults, an environment file such as appsettings.Production.json, then environment variables and command line arguments, with later sources overriding earlier ones. In code I never read raw keys. I bind each section to a typed options class and validate it, with data annotations or a custom validator set to run at startup, so a missing setting stops the app at deployment rather than at midnight. Secrets never go in appsettings or source control. Locally I use user secrets, which live outside the project folder. In production we keep them in Azure Key Vault, added as a configuration source, and the app authenticates with a managed identity, so there is no credential to store just to reach the vault. For values that change at runtime, IOptionsMonitor picks up reloads, whereas plain IOptions is read once. I also scan for secrets in CI, because sooner or later someone pastes a connection string into a test.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What is the difference between IOptions, IOptionsSnapshot and IOptionsMonitor?
- How would you rotate a database password without downtime?
- Why are environment variables not a complete answer for secrets?
Related .net developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions