A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
I have string BingMapsApiKey in HomeController.cs I want to move it to appsettings.json. Please suggest
The following snippet was copied from the official documentation.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"BingMapsApiKey": "123456789"
}
Controller
public class ConfigController : Controller
{
private readonly IConfiguration Configuration;
public ConfigController(IConfiguration configuration)
{
Configuration = configuration;
}
public IActionResult Index()
{
return Ok(Configuration["BingMapsApiKey"]);
}
}