Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 223
n0idea Avatar asked Dec 19 '13 12:12

n0idea


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();
like image 169
pranav rastogi Avatar answered Oct 19 '22 19:10

pranav rastogi


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.

like image 1
O.Taaffe Avatar answered Oct 19 '22 18:10

O.Taaffe