如果单击后退按钮,则使上一页过期 [英] Expire previous Page if the back button is clicked

查看:64
本文介绍了如果单击后退按钮,则使上一页过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如果单击浏览器的后退按钮,我试图使上一页过期.我尝试了以下步骤:

步骤#1

Hi All,

I am trying to expire previous page if the back button of browser is clicked. I have tried the following steps:

Step #1

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



步骤#2



Step #2

<%@ OutputCache Duration="1" NoStore="true" VaryByParam="none" %>



步骤#3



Step #3

Response.Expires = -1;



不幸的是,它们都不起作用.

我该怎么办?

问候
Aman



Unfortunately, None of them work.

How Should I do this?

Regards
Aman

推荐答案

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetNoStore();
        Session.Abandon();

and
Collapse
<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>


您在做正确的事情.根据我的PHP经验,您需要进行设置:
缓存控制:无
语法:无缓存
过期:(过去的日期/时间)
...以使浏览器不缓存页面.

请注意,虽然这与防止后退按钮正常工作并不一定是同一回事.您不应该尝试这样做,作为网站用户,这很烦人.某些浏览器不会将返回视为页面刷新,因此不会进行缓存检查.

你为什么要这样做?大多数用例可以通过注销时清除会话来解决,这将导致所有与会话相关的内部页面失败(通常是通过重定向到登录页面).
You are doing the right things. You need to set, from my PHP experience:
Cache-Control: none
Pragma: no-cache
Expires: (a date/time in the past)
... to get browsers not to cache the page.

Note that that is not necessarily the same thing as preventing the back button working, though. You shouldn''t try to do that, it is very annoying as a website user. Some browsers will not count going back as being a page refresh and therefore won''t do a cache check.

Why do you want to do this? Most use cases can be solved by clearing the session on logout, which will cause all session-dependent internal pages to fail (usually by redirecting to a login page).


请参阅本技巧/绝招

注销后浏览器后退按钮问题 [
Look at this Tip/Trick.

Browser back button issue after logout[^]


这篇关于如果单击后退按钮,则使上一页过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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