How to read appsettings.json in my _layout.chtml
In .net core mvc you can inject the configuration by adding the following two lines at the top of your view:
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
You can then access the value like this:
@Configuration.GetSection("ApplicationInsights")["InstrumentationKey"]
If you use the options pattern you can inject them into your view like this:
@using Microsoft.Extensions.Options
@inject IOptions<ApplicationInsightsOptions>
ApplicationInsightsOptionsAccessor
@
{
var instrumentationKey =
ApplicationInsightsOptionsAccessor.Value.InstrumentationKey;
}
Options pattern in ASP.NET Core