1
votes

I have been trying to understand the appsettings.json method of use for some time now as I am building an ASP.NET Core 3.1 API that is to be published to Azure.

When I'm publishing the project to my web app my settings don't seem to get copied to the App Service configurations list in the Azure App Service resource.

Is this how it is supposed to work or am I missing something here?

I've read about appconfigurationbuilder and such, but as I understand it it's for telling the application which appsettings.json file to use depending on what environment is defined in the environment variable (ASPNETCORE_ENVIRONMENT) for example.

Though having a bunch of Key Vault references in my config, this doesn't work as my references of type:

@Microsoft.Keyvault(SecretUri=[KEY VAULT SECRET URL])

Can't fetch the secret from keyvault by only being the the appsettings.env.json file and not being copied to the app service configurations where they connect to keyvault through identity principal.

What am I missing or have I misunderstood the whole thing with appsettings.json?

So short recap: what I'm trying to do is understand if app settings can work like this:

appSettings.Env.json --> publish project to Azure app service --> settings are set automatically in app service configuration.
1
I believe you will have to create appsettings.json on azure separately..gkb
"my settings don't seem to get copied to the App Service configurations list" - this is normal. Those Configuration values in the Azure Portal are optional and are used to override any values in the appsettings files, usually with only the instance/environment-specific values (and secrets that don't belong in the appsettings files).sellotape
@sellotape Hmm.. so whats the solution to this, implementing all keyvault secrets in app service configuration manually? So coming for a background of once used a web.config my reasoning was appsettings.json was the substitute for that in CORE 3.1? Common misunderstanding? I mean after a bit of configuration in the app i pretty much use it the same way in the code, that it getting variables globally from it just as i did the web.config...John
It’s well worth reading the official docs on this; they explain everything pretty well, including using Vault secrets. You should largely try to forget everything you were used to with web.config when moving across; the new way is a lot more flexible.sellotape
@JoyWang I guess not as my initial though of the whole process isnt even how appsettings.json is supposed to be used so i think i got my asnwer in a way. Just marked and upvoted the valid comments and posts so i guess i'll go from there.John

1 Answers

0
votes

As mentioned in the comment, the app settings will not be copied to the azure app service when published, you need to specify the values in it manually.

Follow this doc - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0#azure-app-service