Advertisement
Intermediate ASP.NET Core, Configuration & Options Pattern

What is user secrets (dotnet user-secrets), and why should it be used only for local development, never production?

Short answer

User secrets stores sensitive configuration values (API keys, connection strings) outside the project directory in a per-user, per-project JSON file, keeping them out of source control accidentally while still being automatically loaded into IConfiguration during local…

Save ASP.NET Core mock interview
Advertisement
AModel answer
User secrets stores sensitive configuration values (API keys, connection strings) outside the project directory in a per-user, per-project JSON file, keeping them out of source control accidentally while still being automatically loaded into IConfiguration during local development -- it's explicitly unencrypted, plain text on local disk, making it entirely unsuitable for production, where a proper secret manager (Azure Key Vault, AWS Secrets Manager) should be used instead.
dotnet user-secrets init
dotnet user-secrets set "ConnectionStrings:Db" "Server=local;Database=Dev;"

// Automatically loaded in Development via:
// builder.Configuration.AddUserSecrets<Program>();  (added by default host builder in dev)
Real-world example
A developer avoids accidentally committing their local database password to a shared Git repository by storing it in user secrets instead of directly in appsettings.Development.json, which would otherwise get committed alongside the rest of the code.
Likely follow-ups
  • Where are user secrets actually stored on disk?
  • Why is user secrets specifically excluded from being enabled by default in Production?
Related topics