'Which way to fetch value from local.settings.json?
Could someone please explain which way, if any of these, is the preferred way of fetching values in Startup class from local.settings.json, C# .NET6. The startup.cs is for a function.
client.BaseAddress = new Uri(configuration["BaseEndpoints:RestIg"]);
client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("BaseEndpoints:RestIg"));
client BaseAddress = new Uri(configuration.GetSection("BaseEndpoints:RestIg").Value);
In my local.settings.json I can have the value of BaseEndpoints:RestIg either inside or outside the values{}, not sure where I would want to place it?
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TimerInterval": "0 0 * * * *"
},
"BaseEndpoints": {
"RestIg": "https://myurl.com....etc.etc.etc"
}
}
According to this dude Microsoft recommends this method because it works both locally with local.settings.json and in Azure.
i.e.Environment.GetEnvironmentVariable("BaseEndpoints:RestIg");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|