My question is simple. I have an ASP.net core 3.0 app, I added secrets using visualstudio and pasted my secrets into the secret file normally. Then inside my Program.cs, I added a call to addusersecrets as follows:
...
...
.AddUserSecrets<Startup>()
But while calling my secrets like Configuration["Authentication:Secret"]
as I used to do when it was in appsettings.json, I get a null value in return.
I went through stackoverflow and tried solutions like changing my addsecrets as follows:
.AddUserSecrets("fds...-...-...askd")
//OR
.AddUserSecrets(typeof(Startup).Assembly, true, reloadOnChange: true)
BUt none of then works.
I wonder if this secret stuff even works on asp.net core, because I don't see any reason my code doesn't work. please if someone gets it, can you tell me a solution ? Thanks.
Enable secret storage By default, the inner text of UserSecretsId is a GUID. The inner text is arbitrary, but is unique to the project. In Visual Studio, right-click the project in Solution Explorer, and select Manage User Secrets from the context menu.
Your secrets are stored in a JSON file under your user profile. In a Windows machine, they are stored in the %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets. json file.
In Rider's Solution Explorer, right-click on the ASP.NET Core project -> Tools -> Open project user secrets. This opens the secrets. json file for your project allowing you to add, edit, remove items by hand.
Microsoft offers a secret manager tool that allows one to store secrets (in plain text) on the local development PC and these secrets are available locally during application development. These secrets overwrite any settings in appsettings. json and appsettings. {environment}.
Be sure to check that you've set the "ASPNETCORE_ENVIRONMENT"
variable to "Development"
, else your app wont add your user secrets.
in powershell:
$Env:ASPNETCORE_ENVIRONMENT = "Development"
cmd:
setx ASPNETCORE_ENVIRONMENT "Development"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With