ASP.Net MVC 5 w/identity 2.2.0 Log off not working
Solution 1
I had this problem before, change:
AuthenticationManager.SignOut();
To:
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Assuming that you are using ApplicationCookie to store your login information.
Solution 2
Better way :
public ActionResult Logout()
{
SignInManager.AuthenticationManager.SignOut();
return RedirectToAction("Index", "support", new { area = "" });
}
or you can use injected SignInManager into your controller like this :
public ActionResult Logout()
{
_signInManager.AuthenticationManager.SignOut();
return RedirectToAction("Index", "support", new { area = "" });
}
there is no deference.
John S
Been around since the days of Business Basic and the 6502. Currently working mostly in the Microsoft stack, C#, SQL, etc.. Also work with SCSS, CSS, JQuery, Javascript. Currently a Software Engineer that likes to keep up on some aspects of the IT side of things so that I can do a better job writing my software. Always striving to understand the whole problem domain not just the algorithm.
Updated on June 05, 2022Comments
-
John S almost 2 years
I am using a the basic login on a test ASP.Net MVC 5 site (for an internet site).
The login works fine but when I try to logout it doesn't happen. The logout link does call the following controller action:
public ActionResult LogOff() { AuthenticationManager.SignOut(); return RedirectToAction("Index", "Home"); }
But the user stays logged in. How do I ensure that the user actually gets logged out?