【问题标题】:ASP.Net MVC 5 w/identity 2.2.0 Log off not workingASP.Net MVC 5 w/identity 2.2.0 注销不起作用
【发布时间】:2015-04-22 22:00:56
【问题描述】:

我在测试 ASP.Net MVC 5 站点(用于 Internet 站点)上使用基本登录。

登录工作正常,但当我尝试注销时,它不会发生。 注销链接确实调用了以下控制器操作:

public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}

但用户保持登录状态。如何确保用户真正退出?

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-5 logout asp.net-identity-2


【解决方案1】:

我之前也遇到过这个问题,改一下:

AuthenticationManager.SignOut();

收件人:

AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

假设您使用 ApplicationCookie 来存储您的登录信息。

【讨论】:

  • 谢谢 - 为我工作。小提示:应该是AuthenticationManager(根据自动生成的代码)而不是Authentication
  • 实际上并没有从服务器端注销。 stackoverflow.com/questions/24552448/…
  • @JeevaJsb 这个问题是关于不记名令牌的,它与 cookie 完全不同
【解决方案2】:

更好的方法:

public ActionResult Logout()
{
    SignInManager.AuthenticationManager.SignOut();
    return RedirectToAction("Index", "support", new { area = "" });
}

或者您可以像这样使用注入的 SignInManager 到您的控制器中:

public ActionResult Logout()
{
    _signInManager.AuthenticationManager.SignOut();
    return RedirectToAction("Index", "support", new { area = "" });
}

没有尊重。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,无法注销。我会保持登录状态,只重定向回主视图。我使用的是 Chrome,我在 firefox 和 ie 中尝试过,但没有出现问题。然后我用 chrome 清除了我的 cookie,一切正常。如果其他人遇到此问题,这可能是一个快速而简单的第一步。

    【讨论】:

    • 从 AspNet.Identity 2.0.1 升级到 2.2.0 后,我们的应用程序遇到了同样的问题。清除 cookie 确实将用户注销,但这不是一个非常实用的解决方案。我们在接受的答案中实施了修复,它为我们解决了问题。
    猜你喜欢
    • 2015-02-09
    • 1970-01-01
    • 2022-07-08
    • 2013-02-15
    • 2018-05-18
    • 2015-09-30
    • 1970-01-01
    • 2018-09-16
    • 2016-04-27
    相关资源
    最近更新 更多