Reputation: 384
I have a .net (core) 5 application which I am trying to setup so that sensitive values are held in secrets.json file, and when the application is published to Azure I can then use the Application settings area of the app service to provide the values from here instead.
However, I am unable to use both at the same time.
In my secrets.json file I have:
{
"UserName": "LocalUserName"
}
In my appsettings.json file I have:
{
"UserName": ""
}
As I understand that I need the same structure, but without the value assigned to the key.
In my Startup.cs file I can reference:
Username = Configuration["Username"]
Which only gets the blank key in the appsettings.json file instead of the secrets.json file
In the Application settings area I am setting:
{
"name": "Username",
"value": "PublishedUserName",
"slotSetting": false
}
But is not picked up.
I have seen references to use ConfigurationManager.AppSettings["Username"];
instead. But if I use this, then this doesn't reference either of my json files when debugging.
I'm new to using .net core, so I'm struggling. In essence what I'm trying to do is replicate what I would have with an appsettingssecrets.config file outside of the application in a .net framework solution. Which I can then reference the same keys in Azure and provide published values from there.
Upvotes: 2
Views: 6019
Reputation: 3398
Here is a tutorial about how to store appsettings
in secrets.json
.
You could check things below:
UserSecretsId
in your project file?Upvotes: 1