Let’s start with the code. I want to read from my appsettings.json file from within one of my ASP.NET Core controllers, for example.
Table of Contents
.Net 6.x updated 2021-10-27
Configuration in ASP.NET Core 6.x
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0
How to use
.Net 5.x
First, add a setting to the applicationsettings.json file, similar to the following with a name of API_URL, for example and give it a value.
Next, add this line of code to the Startup(IConfiguration configuration) method within the Startup.cs file.
Finally, in the controller of choice, add the following code.
using Microsoft.Extensions.Configuration;