Blazor server logout on SignalR connection break

Mrbanad 30 Reputation points
2024-06-19T20:07:08.9166667+00:00

My Blazor server-side application logs out the user whenever the SignalR connection breaks. For example, when I lock my phone for half an hour and then return to the site, I'm logged out. How can I prevent this from happening?

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
642 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,321 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,468 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 59,556 Reputation points
    2024-06-19T22:30:31.4+00:00

    you can't. on lost connection, the server Blazor instance hangs around for a little while waiting for a reconnect, but it exits as it don't know if the user will every reconnect. The client code just reloads the Blazor app if the Signal/R session can not reconnect.

    if you need the Blazor app to recover from a Signal/R disconnect (and mobile browser are very aggressive at disconnecting, switching tabs will do it) you need to make the app recoverable. The app should save the state to a persistent store (server or local storage). on app load, it should check for the saved state and reset values. each page should check for saved state at init. it must also clear saved state (say when navigating away). a seamless recovery requires saving every keystroke, but this is pretty expensive.