【问题标题】:Does HttpContext.Current.Session gets destroyed when AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);当 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 时,HttpContext.Current.Session 是否被销毁?
【发布时间】:2017-07-07 17:29:20
【问题描述】:

我的代码中有HttpContext.Current.Session["CurrentUser"] = user;,在注销时我有这个

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

我只是想确保在我注销时HttpContext.Current.Session 也被破坏。如果不是,那它怎么销毁呢?

【问题讨论】:

  • MSDN 建议注销后调用会话Abandon()。请参阅链接中的第三个注释。

标签: asp.net-mvc


【解决方案1】:

我认为服务器默认会保留Session 数据 20 分钟,除非你做一些明确的事情。

但是您可以在注销或放弃会话时清除特定的会话变量。

查看这里了解更多信息:What is the difference between Session.Abandon() and Session.Clear()

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2018-08-28
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    相关资源
    最近更新 更多