【问题标题】:How do i remove the session and cookies of mvc 5如何删除 mvc 5 的会话和 cookie
【发布时间】:2015-04-08 10:11:31
【问题描述】:

我有一个我要发布到的电子邮件确认控制器。

发生这种情况时,我需要注销,清除有关用户的会话和 cookie...这是因为当他们确认他们的电子邮件时,我需要一个按钮来让用户重新发送确认电子邮件。

我是这样做的:

[HttpPost]
[Authorize]
public async Task<ActionResult> ReSendEmailConfirmation(string userID)
{
    await this.SendEmailConfirmation( userID );

    //Log off to prevent stale user session
    AuthenticationManager.SignOut( DefaultAuthenticationTypes.ApplicationCookie );
    Session.Clear();
    Session.Abandon();
    Response.Cookies.Clear();

    return RedirectToAction( "ReSendEmailConfirmation" ); // I am logged out okay, but when i goto my email... click the confirmation link, then log back in... it still says my email is not confirmed. If i shut my browser down, it will then update.
}

问题是即使在所有这些之后......

当我重新登录时,它仍然说电子邮件未确认...即使它在数据库中...

如何彻底清除用户会话?

【问题讨论】:

    标签: asp.net-mvc session cookies


    【解决方案1】:

    Session.Clear 将清除所有会话。 Response.Cookies.Clear 将清除所有 cookie。 你可以用[NoCache] 装饰你的动作以防止它被缓存

    【讨论】:

    猜你喜欢
    • 2010-11-08
    • 2022-01-03
    • 2012-09-01
    • 2012-09-10
    • 2013-09-12
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 2017-12-24
    相关资源
    最近更新 更多