Search code examples
asp.net-coreblazorblazor-webassemblyblazor-client-side

Is it possible to have two (multiple) clients hosted on the same server in a Blazor WebAssembly app


I created a Blazor WebAssembly App named "BlazorWebApp" and checked the box for "ASP.NET Core hosted". Now, can I add another client app to access the same server? I tried by adding another Blazor WebAssembly named Client2 and unchecked the box for "Core hosted" , but now it doesn't work, displaying an empty browser. I would like to know how to set the server to select the client that will show after the build and what changes the newly added client needs to communicate with the server. I found this link here but it only solved the conflict error.


Solution

  • Well, you can host multiple WASM files. HOWEVER, the problem occurs with the path/route mapping. When you fetch a WASM page (say "/site1/page1") the host will not find it locally and fall-back to a certain path (set in Startup.cs: e.g. "endpoints.MapFallbackToPage("/Index");"). From there it will download the WASM to the client and next resolve the mapping within the WASM.

    So you can now imagine the problem when hosting two WASM clients: say you have a second site "/site2/page1", the default fallback will just always download the first WASM, and not find the page within that.

    You will probably have to write your own "FallbackTo..." which maps specific path/routes to specific WASM clients. Likely possible, but also likely it will take some effort.

    edit: I just found that Microsoft Docs actually have an entrie on this topic: Hosted deployment with multiple Blazor WebAssembly apps