禁用页面缓存以强制使用浏览器后退按钮加载页面

发布于 2024-07-20 16:29:32 字数 515 浏览 2 评论 0原文

我有一个 asp.net 网站,该网站在页面上使用更新面板,但我无法从服务器重新加载。 我有这个用于禁用母版页上的页面缓存。

     Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
     Response.Cache.SetValidUntilExpires(False)
     Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
     Response.Cache.SetCacheability(HttpCacheability.NoCache)
     Response.Cache.SetNoStore()

当我单击浏览器后退按钮返回页面时,它说该页面已过期。 我网站上的其他页面可以工作并调用页面加载,我找到但无法使用的唯一解决方案是将整个页面包装在更新面板中,但我无法执行此操作,因为我在页面上有一个报告查看器不适用于ajax。 如果有人可以提供帮助,我将非常感激。

I have an asp.net website that is using update panels on the page that i cant get to reload from the server. I have this for the disable page cache on the master page.

     Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
     Response.Cache.SetValidUntilExpires(False)
     Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
     Response.Cache.SetCacheability(HttpCacheability.NoCache)
     Response.Cache.SetNoStore()

When I click the browser back button to go back to the page it says the page has expired. The other pages on my web site work and call the page load, the only solution i found but cant use is to wrp the whole page in an update panel, but i can't do this because i have a report viewer on the page that does not work with ajax. If anyone can help i would deeply appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酷到爆炸 2024-07-27 16:29:32

这不是浏览器缓存问题;而是浏览器缓存问题。 这是一个回发的。 您必须实现 Post/Redirect/Get 模式,以避免出现“您要再次提交吗?/页面已过期”消息。

http://en.wikipedia.org/wiki/Post/Redirect/Get

一个典型的例子是网页有一个保存按钮,可以在数据库中插入一些内容。 点击“保存”按钮-> 发生回发 -> 代码在表中插入一行-> 用户刷新页面(F5)-> 再次发生回发-> 代码再次插入同一行。

为了避免上一个示例中的双重插入,您需要在按下“保存”按钮时进行重定向,然后才执行插入。

This is not a browser cache problem; it's a postback one. You have to implement the Post/Redirect/Get pattern in order to avoid the "do you want to submit again? / page expired" message.

http://en.wikipedia.org/wiki/Post/Redirect/Get

The classic example for this thing is when a web page has a save button that insert something in a Database. The "Save" button is clicked -> a postback occurs -> code insert a row in a table -> user refres the page (F5) -> postback occurs again -> code insert the same row again.

To avoid the double insert in the previous example you need to redirect when the "save" button is pressed and only then, execute the insert.

成熟的代价 2024-07-27 16:29:32

只需将其添加到视图文件的标头部分:

<head>
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>
</head>

在正文标记内添加以下内容:

<body onUnload="OperaReload()">
<input type="hidden" id="refreshed" value="no">

Just add this in your view file in header part:

<head>
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>
</head>

Inside body tag add this:

<body onUnload="OperaReload()">
<input type="hidden" id="refreshed" value="no">
孤星 2024-07-27 16:29:32

要使用 JavaScript 重新加载页面,请使用以下命令:

window.location.replace(window.location.pathname);

To reload the page with JavaScript use the following:

window.location.replace(window.location.pathname);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文