上登出MVC 4清除会话 [英] Clear session on Logout MVC 4

查看:353
本文介绍了上登出MVC 4清除会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在MVC 4 asp.net上登出清除会话
 我已经试过几乎所有的事情,但一切都是徒劳。

I need to know how to clear session on Logout in MVC 4 asp.net I have tried almost every thing but all in vain.

    [AllowAnonymous]
    public ActionResult SignOut()
    {
        Response.AddHeader("Cache-Control", "no-cache, no-store,must-revalidate");
        Response.AddHeader("Pragma", "no-cache");
        Response.AddHeader("Expires", "0");
        Session.Abandon();

        Session.Clear();
        Response.Cookies.Clear();
        Session.RemoveAll();

        Session["Login"] = null;
        return RedirectToAction("Index", "Login");
    }

Session.Clear();

     Session.Abandon();

 清除Cookies

 设置会话为NULL,注销等

Session.Clear();
Session.Abandon();
Clear cookies
set session to Null on Logout etc

但是当我点击浏览器的后退按钮。重定向到同一个帐户。
请帮帮我,我将如何清晰的会话变量时,我清楚的注销按钮。
我被一个,然后在组,但同样的结果尝试每其中之一。

but when i click on Browser's back button . it redirect to the same account. please help me , how would i clear session variable when i clear on logout button. I tried each of these one by one and then in group but same result.

推荐答案

当你点击浏览器后退按钮,它从高速缓存无法从服务器带来的页面。但是,用户将无法后退按钮后显示的页面上执行任何操作。

When you click on browser back button, it brings page from cache not from server. But user will not be able to perform any action on page displayed after back button.

如果你仍然想页面不应该显示你应该删除缓存。这是一个最好的做法。这里是code。 (在文件的Global.asax.cs写入)

If you still want page should not be displayed you should remove cache. It's a best practice. Here is the code. (Write in Global.asax.cs file)

 protected void Application_BeginRequest()
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
        Response.Cache.SetNoStore();
    }

写这篇code用户将看不到后pressing后退按钮previous页面后。

After writing this code user will not see previous page after pressing back button.

上面写尽Session对象明确的code是正确的。无需改变任何事情。

这篇关于上登出MVC 4清除会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆