ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have string BingMapsApiKey = "Au7sMtQzyQZRzuQ2krOIbZg8j2MGoHzzOJAmVym6vQjHq_BJ8a1YQGX3iCosFh8u"; in HomeController.cs I want to move it to appsettings.json.
Please suggest
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"]);
}
}