You want to use the user secrets API. See my example below (based on ASP.NET 5 Beta 5):
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder( applicationEnvironment.ApplicationBasePath);
You should also set userSecretsId in project.json (see links below). This is a unique identifier for your project secrets and will be needed below when you create a new secret:
{ "webroot": "wwwroot", "userSecretsId": "[Your User Secrets ID]", "version": "1.0.0-*" ... }
To add / remove / update user secrets, you need to install the secret manager by doing:
dnu commands install SecretManager
Then use the secrets manager to actually add / remove / update the settings:
Usage: user-secret [options] [command] Options: -?|-h|--help Show help information -v|--verbose Verbose output Commands: set Sets the user secret to the specified value help Show help information remove Removes the specified user secret list Lists all the application secrets clear Deletes all the application secrets Use "user-secret help [command]" for more information about a command.
See this and this documentation for more information.
It should also be noted that from the moment of writing (ASP.NET 5 Beta 5) the user's secrets are not encrypted! This will change later.
Muhammad Rehan Saeed
source share