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

Murugan Andezuthu Dharmaratnam | 07 March 2021 | 68

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");
}