如何清除MVC5中的所有会话 [英] How to clear all session in mvc5

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

问题描述

我在登录到asp.net mvc应用程序中的特定管理页面时创建了一个会话.当我单击注销时,它会按照指示将我重定向到注销页面,但是当我单击后退导航"按钮时,它将使我返回到我从中注销的页面.
我要防止的是,注销后,然后单击后退导航"按钮,我不想返回上一页.它应该告诉我会话已过期或将我重定向到登录页面.

这是位于我的布局页面中的注销按钮

 <   ul      ="  > 
       <   li  >  @Html. ActionLink(注销",注销",主页")<  /li  > 
<  /ul  >  



这是我的控制器代码

 公共 ActionResult注销()
        {
            Session.Abandon();
            @tempData [" ] = Session.Mode;
            返回 View();
        } 


当我在注销页面上检查会话模式时,它向我显示InProc

解决方案

当您单击浏览器后退按钮时,它将带出一个来自缓存的页面.为防止这种情况,您可以按照以下方式删除缓存:

 Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore(); 



您还可以在视图中添加一个元数据,以清除缓存.

检查此讨论以获取有关解决方法的详细信息:<ul class="right chevron"> <li>@Html.ActionLink("Log Out", "logout", "Home")</li> </ul>



this is my controller code

public ActionResult logout()
        {
            Session.Abandon();
            @tempData["sess"] = Session.Mode;
            return View();
        }


when i check the session mode on the logout page, it shows me InProc

When you click on browser back button, it brings a page from cache. To prevent this you could remove the cache like the following:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();



You can also add a meta to your view that clears the cache.

Check this discussion for details of the workaround:
asp.net mvc - After logout if browser back button press then it go back last screen - Stack Overflow[^]


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

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