s

getting value from appsettings.json in asp .net core 5.0 mvc edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 07 March 2021 | 1284

how can I read a string value from appsettings.json in asp .net core 5.0 MVC. In my application, I have to read API_URL from appsettings.json file.

Solution

in appsettings.json add API_URL


{
  "AllowedHosts": "*",
  "API_URL": "https://tessaextractkeyword.azurewebsites.net/"
}


in startup.cs 

public Startup(IConfiguration configuration, IHostEnvironment HostEnvironment)
{
            Configuration = configuration;
            String  url = Configuration.GetValue("API_URL");
}