Blazor

How do I access the appsettings in Blazor WebAssembly?

How do I access the appsettings in Blazor WebAssembly?

Configurations loaded by the Blazor WebAssembly can be accessed by injecting IConfiguration services. Using IConfiguration, the values from wwwroot/appsettings.json and wwwroot/appsettings.{ENVIRONMENT}.json files can be accessed.

wwwroot/appsettings.json

{
  "message":  "Blazor is awesome."   
}

Index.razor

@inject Microsoft.Extensions.Configuration.IConfiguration config
 
<span>@config["message"]</span>

For more information about the configuration check, the below-given link:

https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/additional-scenarios?view=aspnetcore-3.1#configuration

Sumitra Kumari Shaw

An Engineering graduate who Enjoys building things that live on the internet.