--- title: ASP.NET Core Blazor configuration author: guardrex description: Learn about configuration of Blazor apps, including app settings, authentication, and logging configuration. monikerRange: '>= aspnetcore-3.1' ms.author: riande ms.custom: mvc ms.date: 12/10/2020 no-loc: [Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR] uid: blazor/fundamentals/configuration --- # ASP.NET Core Blazor configuration > [!NOTE] > This topic applies to Blazor WebAssembly. For general guidance on ASP.NET Core app configuration, see . Blazor WebAssembly loads configuration from the following app settings files by default: * `wwwroot/appsettings.json`. * `wwwroot/appsettings.{ENVIRONMENT}.json`, where the `{ENVIRONMENT}` placeholder is the app's [runtime environment](xref:fundamentals/environments). Other configuration providers registered by the app can also provide configuration, but not all providers or provider features are appropriate for Blazor WebAssembly apps: * [Azure Key Vault configuration provider](xref:security/key-vault-configuration): The provider isn't supported for managed identity and application ID (client ID) with client secret scenarios. Application ID with a client secret isn't recommended for any ASP.NET Core app, especially Blazor WebAssembly apps because the client secret can't be secured client-side to access the Azure Key Vault service. * [Azure App configuration provider](/azure/azure-app-configuration/quickstart-aspnet-core-app): The provider isn't appropriate for Blazor WebAssembly apps because Blazor WebAssembly apps don't run on a server in Azure. > [!WARNING] > Configuration in a Blazor WebAssembly app is visible to users. **Don't store app secrets, credentials, or any other sensitive data in the configuration of a Blazor WebAssembly app.** For more information on configuration providers, see . ## App settings configuration Configuration in app settings files are loaded by default. In the following example, a UI configuration value is stored in an app settings file and loaded by the Blazor framework automatically. The value is read by a component. `wwwroot/appsettings.json`: ```json { "h1FontSize": "50px" } ``` Inject an instance into a component to access the configuration data. `Pages/ConfigurationExample.razor`: ```razor @page "/configuration-example" @using Microsoft.Extensions.Configuration @inject IConfiguration Configuration

Configuration example

``` To read other configuration files from the `wwwroot` folder into configuration, use an to obtain the file's content. The following example reads a configuration file (`cars.json`) into the app's configuration. `wwwroot/cars.json`: ```json { "size": "tiny" } ``` Add the namespace for to `Program.cs`: ```csharp using Microsoft.Extensions.Configuration; ``` In `Program.Main` of `Program.cs`, modify the existing service registration to use the client to read the file: ```csharp var http = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }; builder.Services.AddScoped(sp => http); using var response = await http.GetAsync("cars.json"); using var stream = await response.Content.ReadAsStreamAsync(); builder.Configuration.AddJsonStream(stream); ``` ## Memory Configuration Source The following example uses a in `Program.Main` to supply additional configuration. Add the namespace for to `Program.cs`: ```csharp using Microsoft.Extensions.Configuration.Memory; ``` In `Program.Main` of `Program.cs`: ```csharp var vehicleData = new Dictionary() { { "color", "blue" }, { "type", "car" }, { "wheels:count", "3" }, { "wheels:brand", "Blazin" }, { "wheels:brand:type", "rally" }, { "wheels:year", "2008" }, }; var memoryConfig = new MemoryConfigurationSource { InitialData = vehicleData }; builder.Configuration.Add(memoryConfig); ``` Inject an instance into a component to access the configuration data. `Pages/MemoryConfig.razor`: ```razor @page "/memory-config" @using Microsoft.Extensions.Configuration @inject IConfiguration Configuration

Memory configuration example

General specifications

  • Color: @Configuration["color"]
  • Type: @Configuration["type"]

Wheels

  • Count: @Configuration["wheels:count"]
  • Brand: @Configuration["wheels:brand"]
  • Type: @Configuration["wheels:brand:type"]
  • Year: @Configuration["wheels:year"]
``` Obtain a section of the configuration in C# code with . The following example obtains the `wheels` section for the configuration in the preceding example: ```razor @code { protected override void OnInitialized() { var wheelsSection = Configuration.GetSection("wheels"); ... } } ``` ## Authentication configuration Provide authentication configuration in an app settings file. `wwwroot/appsettings.json`: ```json { "Local": { "Authority": "{AUTHORITY}", "ClientId": "{CLIENT ID}" } } ``` Load the configuration for an Identity provider with in `Program.Main`. The following example loads configuration for an [OIDC provider](xref:blazor/security/webassembly/standalone-with-authentication-library). `Program.cs`: ```csharp builder.Services.AddOidcAuthentication(options => builder.Configuration.Bind("Local", options.ProviderOptions)); ``` ## Logging configuration Add a package reference for [`Microsoft.Extensions.Logging.Configuration`](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Configuration) to the app's project file: ```xml ``` In the preceding example, the `{VERSION}` placeholder is the package's version. Package versions are found at [NuGet.org](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Configuration). In the app settings file, provide logging configuration. The logging configuration is loaded in `Program.Main`. `wwwroot/appsettings.json`: ```json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } } } ``` Add the namespace for to `Program.cs`: ```csharp using Microsoft.Extensions.Logging; ``` In `Program.Main` of `Program.cs`: ```csharp builder.Logging.AddConfiguration( builder.Configuration.GetSection("Logging")); ``` ## Host builder configuration Read host builder configuration from in `Program.Main`. In `Program.Main` of `Program.cs`: ```csharp var hostname = builder.Configuration["HostName"]; ``` ## Cached configuration Configuration files are cached for offline use. With [Progressive Web Applications (PWAs)](xref:blazor/progressive-web-app), you can only update configuration files when creating a new deployment. Editing configuration files between deployments has no effect because: * Users have cached versions of the files that they continue to use. * The PWA's `service-worker.js` and `service-worker-assets.js` files must be rebuilt on compilation, which signal to the app on the user's next online visit that the app has been redeployed. For more information on how background updates are handled by PWAs, see .