Asp. Net Identity Logout

How to logout an user logged in with the ASP.Net Identity system?

I tried:

Authentication.SignOut();

But if I use this and then call an API marked with [Authorize] (adding the token as an header) It still returns me the data (instead of Unauthorized).

1

2 Answers

You need to call SignOut on the AuthenticationManager which you can get from the OWIN context.

var AuthenticationManager= HttpContext.GetOwinContext().Authentication;
AuthenticationManager.SignOut();
8

In my case, because i had Authorize attribute in my AccountController with admin role at class level i had to put [AllowAnonymous] attribute to my logout method. May be a solution to you too.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest