How to logout a user on Browser close in Blazor Server

Michael Ofori-Appiah 0 Reputation points

I have a Blazor server application with Authentication and Authorization. I want to know how to logout a user when the user closes the browser tab without clicking the Logout button.

A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,323 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 52,826 Reputation points

    You logout a user by deleting the authentication cookie. The server can not do this if the tab is closed, as this closes the connection to the client. You can detect the signal/r circuit closed.

    then store in a persistent store that the user failed to logout. Then in the next request from that user, force a logout by deleting the cookie.

    0 comments No comments