Secret storage in .NET

Enable secret storage:
Type “dotnet user-secrets init” into Package Manager Console

<UserSecretsId> can be found in .csproj file.

Set a secret (Package Manager Console):
dotnet user-secrets set “ApiKey” “test123”

or to remove it:
dotnet user-secrets remove “ApiKey”

To check if exists:
dotnet user-secrets list
Manage secret through GUI -> right click on project -> Manage User Secrets -> it opens secrets.json

Location of this secrets.json file:


Sample usage:
DI IConfiguration in constructor:
IConfiguration configuration

private IConfiguration _configuration;

Use it:
var test = _configuration[“ApiKey”];

Much more info:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: