How to pass environment variables to Blazor WASM in hybrid Blazor app using .net 8 and Aspire

  Kiến thức lập trình

I have a .Net 8 solution consisting of:

  • An API (.NET 8 WebAPI with Controllers)
  • A Blazor Application (.Net 8 with Interactive Rendering in Auto mode – i.e. there’s a
    Blazor Server assembly and a Blazor WASM assembly)
  • .Net Aspire AppHost

In the AppHost I am passing environment variables to the API and Blazor projects in local development using .WithEnvironment().

One of the environment variables I pass to the Blazor app is the API’s “Base URL”. This is needed to configure the HttpClient in the WASM assembly.

The issue I have is that the WASM assembly doesn’t seem to be able to see the environment variables being passed to the Blazor project by Aspire.

How can I pass the environment variables from my Blazor server app to the Blazor WASM client app that is created along side it and that the Blazor server app references?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT