如何清除MVC5中的所有会话 [英] How to clear all session in 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();
您还可以在视图中添加一个元数据,以清除缓存.
检查此讨论以获取有关解决方法的详细信息: ^ ]
>
i created a session on log-in into a particular admin page in my asp.net mvc application. when i click logout it redirected me to the logout page as instructed but when i click the back navigation button, it sends me back to the page i logged out from.
what i want to prevent is that, after logging out, then i click the back navigation button, i don''t want to go back to the previous page. it should tell me session expired or redirect me to login page.
this is the logout button located in my layout page
<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屋!