how to use blazor server and blazor webassembly together in one project
Asked Answered
K

2

5

I have a project that has two pages and I need to create page one with blazor web assembly and create page two with blazor server side any idea on how to configure the project for this point?

Kerin answered 25/7, 2022 at 16:21 Comment(6)
you cant run a mix of server & wasm together, it's due to happen for .net 7Electrolyze
can I see any reference to show me that happens in .net 7?Kerin
because one of the Microsoft engineers told me it is possibleKerin
youtu.be/3o91I6lD-Bo?t=3179 see that slide top right first item where it shows "Mix Blazor Server and WebAssembly" , however this is wish list of what we may or not get, I'm watching this space keenly, if you do find anything please postback..!Electrolyze
I found this itnext.io/…Kerin
The configuration on Server for Blazor WASM and Blazor Server its too different. in .NET 6.0 you can not mixed this two type of Blazor projects.Tiptoe
K
5

This future will be available in Blazor .net 8 for more information, visit .net 8 preview 5 features Learn More at Microsoft docs

Kerin answered 14/3, 2023 at 14:2 Comment(0)
C
3

The two hosting models cannot be mixed in one project at the time (in NET 6.0), as far as I know. However, there may be certain workarounds that provide what you need for your use case. Granted, I have little insights into your use case and why you would need a page from different hosting models, so these may not work for you.

Alternative 1:

You can use the third hosting model option, Blazor WASM Hosted, which is a Blazor WASM client served from an ASP.NET Core server project. With this, you can do everything you need on both client- and server-sides. This hosting model provides a lot of flexibility and advantages (e.g. prerendering). While it mainly uses HTTP to communicate between the two, you can use SignalR as well.

Alternative 2:

Alternatively, you could make two separate projects (one WASM and one Server) that you point to the same domain (with either a subdirectory for each, or different subdomains). It's more work to host this, and you may need to different build pipelines - still, it may work for your needs if the two pages are separate and independent.


Edit: This is coming to .NET 8 and Blazor United.

Cataract answered 10/9, 2022 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.