4

我需要一些页面不要缓存在经典 ASP 应用程序上,但我已经尝试了所有可能的标题组合,但似乎没有任何效果:

Response.Expires         = -1
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl    = "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0"
Response.AddHeader         "Cache-Control", "no-cache; private; no-store; must-revalidate; max-stale=0; post-check=0; pre-check=0; max-age=0"  ' Same as previous line, I know, just in case.
Response.AddHeader         "Pragma", "no-cache"
Response.AddHeader         "Expires", "-1"

我也尝试重新启动网站和 IIS,但无济于事。当我离开页面并使用浏览器的后退按钮返回时,它不会重新加载。

我在这里想念什么?

编辑:经过大量的谷歌搜索,我找到并实现了这个 JavaScript 解决方案,它不是防弹的,因为它是客户端的,我更喜欢服务器端的解决方案,但它可以完成工作!

不过,我想听听任何服务器端选项。

4

4 回答 4

9

You are operating under the impression that the result of the browser's back button is related to HTTP caching, it is not.

The provision of the back button is at the discretion of the browser which is from a HTTP stack point of view the application. An application has no obligation to consider the caching requirements of any http request(s) that was used to render the contents of a window. Indeed many browsers are capable of displaying content delivered through other protocols than http.

Consider the most common scenario for using the back button. A user gets some search results from a web search engine (google, bing, ...), clicks on one of the results, quickly sees that the content is not what they were looking for and clicks the back button. In order to optomise the user's experience most browsers will hold on to many of the resources (even the window into which the page is rendered) of a page when navigation from the page occurs. The back button can then be implemented by reassembling those resources or even simply making the original window visible again.

于 2012-09-06T07:27:33.150 回答
5

看起来不错..尝试使用它。

在向用户发送任何 HTML之前运行这些语句,即在任何Response.Write或之前<%=foo()%>

Response.Buffer = True
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1

更正了拼写错误的单词响应。

于 2012-09-06T04:17:50.267 回答
1

当您按下后退按钮时,某些浏览器总是会缓存。有一种方法可以捕捉资源管理器的事件后退按钮并做一些事情,尽管可能很可怕。您可以通过 AJAX 加载页面数据,并使用通过 javascript 生成的随机变量来防止缓存。如果您需要示例,请告诉我...

于 2013-09-13T07:55:26.173 回答
0

防止在经典 ASP 上缓存特定页面。请尝试以下代码:

<% Response.CacheControl = "no-cache, no-store, must-revalidate" %>

在部分下添加上面的代码。

于 2016-12-21T12:38:35.013 回答