How can I logout (Identity) in code in a Blazor server app

David Thielen 3,141 Reputation points
2023-05-25T19:55:43.9166667+00:00

Hi all;

In my code I handle a DbUpdateConcurrencyException and for the case of updating a user's account, and the user no longer exists, I want to log them out - as they are no longer a valid user.

Granted, not a biggie because this should be rare and any page they try to go to will not accept them as they no longer have a claim. But its cleaner to log them out.

I can't use the SignInManager in Blazor. It requires a POST to LogOut.cshtml. So, what's my options?

thanks - dave

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,672 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 68,236 Reputation points
    2023-05-25T20:34:38.3866667+00:00

    just create a logout razor page that calls:

    _signInManager.SignOutAsync();
    

    the via javascript interop redirect to the page


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.