Home > front end >  IConfiguration does not retrieve values from appsettings.json but from Azure Key Vault
IConfiguration does not retrieve values from appsettings.json but from Azure Key Vault

Time:05-13

Inside the Program.cs file of a .NET Core 3.1 Web API i got the following:

    public class Program
{

    private static string _someValue;

    public Program(IConfiguration configuration)
    {
        _someValue = configuration["SOME_VALUE"]

    }

inside the appsettings.json i got:

{
 "Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
    }
},
 "SOME_VALUE": "value"

}

The problem is, i am not able to get the value "SOME_VALUE" from the appsettings.json. But i got this same value inside an Azure Key Vault and for some reason it gets the values from there. Can someone explain why that is the case?

CodePudding user response:

Configuration providers are executed in a specific order enter image description here

In your case, the Azure KeyVault will be at the top (or, to be more precise it is between AddUserSecrets and AddEnvironmentVariables)

See docs

Order configuration providers in code to suit the priorities for the underlying configuration sources that the app requires or use different variable name

  • Related