How do you manage secrets for a .NET app locally and in production?

IntermediateConcept.NET builds (dotnet CLI)
Answer

Short answer

Locally, use User Secrets (dotnet user-secrets), which stores secrets outside the project folder so they're never committed. In production, load them from Azure Key Vault (directly via the Key Vault configuration provider with a managed identity) or inject them as environment variables from Kubernetes Secrets / App Service settings.

Local

dotnet user-secrets init
dotnet user-secrets set "ConnectionStrings:Default" "Host=localhost;Password=devpass"
# stored in ~/.microsoft/usersecrets/<id>/secrets.json — not in the repo

Production with Key Vault + managed identity

builder.Configuration.AddAzureKeyVault(
    new Uri("https://shop-kv.vault.azure.net/"),
    new DefaultAzureCredential());   // uses the app's managed/workload identity, no password

A Key Vault secret named ConnectionStrings--Default maps to ConnectionStrings:Default.

Never

Put real passwords in appsettings.Production.json committed to Git.

What to say in the interview

"User Secrets for local development, Azure Key Vault in production accessed with DefaultAzureCredential and a managed or workload identity, so there are no stored credentials at all. On Kubernetes, the alternative is External Secrets syncing Key Vault into Secrets exposed as env vars."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: .NET apps: dotnet build & publish

More on .NET builds (dotnet CLI)