ASP.Net MVC 5 w/identity 2.2.0 Log off not working

天涯浪子 提交于 2019-11-30 12:26:25

问题


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?


回答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.




回答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.




回答3:


I had the same problem of not being able to logout. I would stay logged in and only redirect back to the home view. I was using Chrome and I tried it in firefox and ie and didn't have the problem. Then I cleared my cookies in chrome and it all worked fine. It could be a quick and easy first step if other encounter this problem.



来源:https://stackoverflow.com/questions/28642284/asp-net-mvc-5-w-identity-2-2-0-log-off-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!