This project uses User Secrets for local development configuration, following .NET best practices.
User Secrets is a .NET feature that stores sensitive configuration data outside your project directory:
- Location:
~/.microsoft/usersecrets/<UserSecretsId>/secrets.json - Never committed to git
- Automatically loaded in Development environment
- Per-developer configuration
./setup.shThe script will automatically configure your connection string in User Secrets.
# Set connection string
dotnet user-secrets set "ConnectionStrings:DefaultConnection" \
"Server=localhost,1433;Database=DotNetWebAppDb;User Id=sa;Password=YourPassword;TrustServerCertificate=True;"
# List all secrets
dotnet user-secrets list
# Remove a secret
dotnet user-secrets remove "ConnectionStrings:DefaultConnection"
# Clear all secrets
dotnet user-secrets clear- DotNetWebApp.csproj contains a
<UserSecretsId>- this identifies your secrets store - appsettings.json has the production connection string (or placeholder)
- appsettings.Development.json has development-specific settings (no secrets)
- User Secrets override both files in Development environment with your local secrets
.NET loads configuration in this order (later sources override earlier ones):
appsettings.jsonappsettings.{Environment}.json- User Secrets (Development environment only)
- Environment variables
- Command-line arguments
✅ Secure: Secrets never appear in your project directory or git ✅ Convenient: Automatically loaded in Development environment ✅ Standard: Official .NET approach for local development ✅ Per-developer: Each team member has their own configuration
You can also use environment variables:
export ConnectionStrings__DefaultConnection="Server=localhost,1433;Database=DotNetWebAppDb;User Id=sa;Password=YourPassword;TrustServerCertificate=True;"Note the double underscore __ to represent the nested ConnectionStrings:DefaultConnection key.
.NET does not load .env files automatically. If you use direnv, make sure your .envrc exports the connection string (you can source .env.local if you prefer):
export ConnectionStrings__DefaultConnection="Server=localhost,1433;Database=DotNetWebAppDb;User Id=sa;Password=YourPassword;TrustServerCertificate=True;"Then run:
direnv allowFor production, use:
- Azure: App Service Configuration or Key Vault
- AWS: Systems Manager Parameter Store or Secrets Manager
- Docker: Environment variables or secrets management
- Kubernetes: Secrets or ConfigMaps
User Secrets are only for local development and are not deployed with your application.