用户仍然在AuthenticationManager.SignOut()之后登录

时间:2015-02-26 15:18:29

标签: asp.net asp.net-mvc asp.net-identity

当我在控制器中注销用户时,User.Identity.Authenticated在返回的视图中仍然是真的。

如果我再次刷新页面,则User.Identity.Authenticated为假

    // GET: /Account/SessionExpired
    [AllowAnonymous]
    public ActionResult SessionExpired()
    {
        AuthenticationManager.SignOut();

        //Clear the session
        SessionHelper.Clear();

        return View();
    }

这是正常的吗?

谢谢

3 个答案:

答案 0 :(得分:1)

是的,这是正常的,因为在执行操作之前检查了授权。如果您想在此之前注销,则必须先执行此操作,例如使用自定义属性

答案 1 :(得分:0)

Visual Studio中的标准MVC模板使用RedirectToAction而不是返回View。这样,浏览器会自动重定向到例如来自新请求的主页/索引操作。

答案 2 :(得分:0)

 // GET: /Account/SessionExpired
    [AllowAnonymous]
    public ActionResult SessionExpired()
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

        //Clear the session
        SessionHelper.Clear();

        return View();
    }