Back to results for “User Secrets)”
.NET › Configuration & Options

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

Intermediate

Answer

User secrets stores sensitive configuration values (API keys, connection strings) outside the project directory (in a per-user, per-project JSON file in the user's profile folder), keeping them out of source control accidentally while still being automatically loaded into IConfiguration during local development -- it's explicitly unencrypted and stored in plain text on the local disk, making it entirely unsuitable for production use, 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 environment 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.

Common follow-ups: Where are user secrets actually stored on disk?;Why is user secrets specifically excluded from being enabled in Production by default?