Using user secrets to access sensitive information
In this demo, i m using user secrets to access sensitive information which need to be kept out of source control :
credentials
connection strings
api keys
etc.
๐ Enabling user secrets in .net projects can be done using :
Visual Studio (Right click on the project
Appand select Manage User Secrets)CLI (Run Command
dotnet user-secrets init --project Appin your Terminal)
๐ After enabling user secrets, an id UserSecretsId is added in the csproj project file.
๐ User Secrets are stored without encryption outside of the project tree in this path :
For Windows :
%APPDATA%\Microsoft\UserSecrets\<UserSecretsId>\secrets.jsonFor Linux/macOS :
~/.microsoft/usersecrets/<UserSecretsId>/secrets.json
๐ User Secrets CLI tool provide some interesting commands :
Use
dotnet user-secrets list --project Appto list user secretsUse
dotnet user-secrets set SomeSecretKey SomeSecretValue --project Appto set user secretsUse
dotnet user-secrets clear --project Appto clear user secrets
๐ User Secrets should be used only for local development and never in production.
- For production, you can use
Azure Key Vaultorappsettings.Production.jsonfile.
Tools : vs22, net 6.0, user-secrets