ASP.NET Core Blazor is a web framework designed to run client-side in the browser on a WebAssembly-based .NET runtime (Blazor WebAssembly) or server-side in ASP.NET Core (Blazor Server), but these two models  cannot be used at the same time. More information about hosting models is available  in the documentation.

This article describes how to

  • run Server and WebAssembly simultaneously in one application,
  • switch from Server to WebAssembly in runtime without reloading the application,
  • implement universal Cookie-based authentication mechanism,
  • sync Server and WebAssembly state using gRPC.

Introduction: why we need it

Both hosting models have their pros and cons:

Blazor Server pros:

  • Small size of resources to download (~250 KB).
  • Fast loading.
  • Responsive UI.

Blazor Server cons:

  • Since DOM changes are calculated on the server, a responsive UI needs a reliable and fast connection to the server.
  • If the connection is broken, the application in the browser will stop working.
  • If the server is restarted, the browser application will stop working and the interface state will be lost.
  • Difficult to scale, as the client will only work with the server that stores its state.

#blazor #webassembly #grpc #aspnetcore

Blazor: Switching Server and WebAssembly At Runtime
6.20 GEEK