Share via

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

David Thielen 3,231 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

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,981 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

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

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