Blazor InteractiveServer in .NET 11: restoring page state after scale-in
The author describes a new .NET 11 feature for the InteractiveServer mode of ASP.NET Core Blazor. Until now, circuits[1] held in server memory could not be moved to another server during scale-in[2], so systems that scale out and in could not be built on this mode. In .NET 11, the server can have the client save its state and then reconnect, so the state is saved before scale-in and the user is sent to another server. The official documentation calls this server-triggered circuit pause.
The author tested the feature in a project from the Aspire starter template, without Redis. The framework has no high-level setup API, so the author wrote a ShutdownCircuitOptions class with a 10-second default timeout. A CircuitShutdownService keeps active circuits in a ConcurrentDictionary and asks each one to pause when the application stops. A CircuitHandler registers circuits on connect and unregisters them on disconnect, and the host shutdown timeout must be more than twice the circuit timeout. On the counter page, the CurrentCount property is marked with PersistentState[3] so that its value is saved.
In the test, the author clicked the counter several times, stopped the frontend process from the Aspire dashboard, and reloaded the page. The counter value was restored. The author notes limits: the connection is dropped once, so the user experience is not ideal, a large amount of state may not save within the timeout, and the state of each page must be designed carefully. The author also wished for a higher-level API.
Sources
-
JPZenn JA
.NET 11 の ASP.NET Core Blazor の新機能のスケールイン対応機能!






