加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – SimpleMembershipProvider不会在WebSecurity.Sig

发布时间:2020-12-16 03:37:58 所属栏目:asp.Net 来源:网络整理
导读:我正在使用所有默认会员代码运行ASP.NET MVC 4. AccountController的LogOff的代码是: [HttpPost] [ValidateAntiForgeryToken] public ActionResult LogOff() { WebSecurity.Logout(); return RedirectToAction("Index","Home"); } 我注意到这段代码不会破坏
我正在使用所有默认会员代码运行ASP.NET MVC 4. AccountController的LogOff的代码是:

[HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult LogOff()
    {
        WebSecurity.Logout();

        return RedirectToAction("Index","Home");
    }

我注意到这段代码不会破坏会话,这意味着如果我使用一个帐户登录,将某些内容保存到会话中,然后注销并使用同一Web浏览器实例中的其他帐户登录,我仍然可以看到上一个用户的会话.

不知道为什么会这样.任何建议将不胜感激.谢谢.

解决方法

Session和Authentification会话不是一回事.

在这里,您销毁了用户的身份验证,但您确实重新启动了ASP.NET会话.

更多解释:https://stackoverflow.com/a/1306932/971693

试着这样做:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    WebSecurity.Logout();

    Session.Abandon();

    // clear authentication cookie
    HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName,"");
    cookie1.Expires = DateTime.Now.AddYears(-1);
    Response.Cookies.Add(cookie1);

    // clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
    HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId","");
    cookie2.Expires = DateTime.Now.AddYears(-1);
    Response.Cookies.Add(cookie2);


    return RedirectToAction("Index","Home");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读