Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to use Azure App Settings in a Blazor WebAssembly Client side application at runtime as appsettings.json configuration?

$
0
0

enter image description here

  • I'm Working on Blazor WebAssembly Client/Server project (directory structure as above)
  • Have some application settings in both client and server projects.
  • The projects are hosted in Azure.

The problem is in the Client side with the appsettings.json

  • In the client side, the appsettings.json is within the wwwroot directory. It is okay to access the file within the app, However, the settings cannot be overwritten by Azure Portal Application Settings of the App service.

It means, that after the app is deployed in Azure portal on a Web App Service, my configuration settings do not work with the application settings' variables.

This is the code in the Progam.cs, which works fine and read the configuration from the file, but ignores the configuration settings of the Web App Service on Azure.

public static async Task Main(string[] args){    var builder = WebAssemblyHostBuilder.CreateDefault(args);    builder.RootComponents.Add<App>("app");    //Add a named httpClient and set base Address and Default Request Headers    builder.Services.AddHttpClient("SOME_WEB_URL", client =>  // SOME_WEB_URL is defined in the appsettings.json or in the Azure App Service configuration (Application Settings)    {        client.BaseAddress = new Uri(builder.Configuration["sbformsapi"]);    });    //Add a named httpClient and set base Address and Default Request Headers    builder.Services.AddHttpClient("WEB_APP_API", client =>   // WEB_APP_API is defined in the     {        client.BaseAddress = new Uri(builder.Configuration["sbwebappapi"]);    });    builder.Services.AddAuthorizationCore();    ....    await builder.Build().RunAsync();}

Could someone please guide how can I either

  • set the appsettings.json file outside the wwwroot and read it from there?OR
  • inject/use the values from Azure App Service configuration's Application settings at runtime?

I am talking about the application settings here (as in the pic)...

enter image description here


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>