简体   繁体   中英

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.

It's eminently possible. Blazor sites aren't really websites per se, but Single Page Applications. The web site is just the launch platform, so you can run as many as you like from the same host site. The trick to making it work is in the configuration. The detailed explanation of how to do it is too much to put in an answer here, so I've provided links below to:

  1. A demo site called Hydra which runs a whole host of Server and WASM SPAs The Mongrel (dog) section is 4 template sites - two Server and two WASM - differentiated by their main colour scheme.
  2. An article on my personal Github site that explains how to do it.

Hydra Site - the Mongrel

Hydra Article

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 : eg "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM