在ASP中不缓存页面

缓存|页面|缓存

Update 1/8/2004
At the top of the page:

<%
pStr = "private, no-cache, must-revalidate"
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", pStr
%>

--------------------------------------------------------------------------------

Don't allow your page to be cached. Why? You might want to prevent users from seeing old content. Insert the following code in the <HEAD> tag of your document.

<meta http-equiv="Expires" content="Tue, 04-Dec-1993 21:29:02 GMT">

Cache No More (ASP)
by Phil Paxton
(Phil@matchw.com)

Here are the things dealing with the issue of caching in ASP:

1. Response.Expires = 0
2. Response.ExpiresAbsolute = Now() - 1
3. Response.AddHeader "cache-control", "private"
4. Response.AddHeader "pragma", "no-cache"
5. Adding a "cachebuster" by creating a unique URL.

Notes:
#1 is said to expire at 60 seconds, not 0. Also, Khin Zaw (from ActiveServerPages@ and ASPAdvanced@) has posted research from time spent with some IIS internals experts revealing this can be a very touchy parameter to rely upon and usually requires a rather "large" negative number or pedantically, that would be a very small number).

#2 (my own creation) says "expire this page 24 hours ago", allowing for time differences, rather than specify a static date.

#3, #4 from an MS KB article. The code is correct but there are some incorrect statements in the article itself.

n.b. some related KB articles include:
(INFO: Controlling the Caching of Web Pages with IIS 4.0)
(PRB: Browser Doesn't Show Most Recent Versions of htm/asp Files)
(How to Use Pragma: No-cache with IIS and IE)

#5 my term, but not my technique. IE 5.0 can defeat #1-#4 used in conjunction but adding #5 will break it. I usually use something like "?NoCache=Rnd" after a statement. Bill Wilkinson (of Chili!Soft) has proposed an alternate of ?NoCache=Server.URLEncode(Now())".

--------------------------------------------------------------------------------

Another thing to remember: Netscape will continue to cache, even if you turn all caching off. This behavior persisted through 4.5 PR1, PR2, and now in the released version of 4.5.

If you fear you might have to deal with caching later, you might want to build contingencies into your app as you go. Retrofitting #5 throughout even a medium-sized app would take a rather sizeable effort. You could retrofit #1-#4 (inclusive) rather quickly with a single pass through the application, but #5 takes a lot of extra effort. And to that end, I don't ever Response.Redirect anywhere in my code except sample code I post to the lists (then again, the only time I use Response.Write is to the list because I rely on my Utilities-Form.inc library for Display() and HTML()). Everything is Redirect(NewURL) where the Redirect function looks like this:

Function Redirect( NewURL )
'
If Not IsEmpty( NewURL & "" ) Then
Dim QuestionMark
'
QuestionMark = Instr( NewURL, "?" )
'
If QuestionMark = 0 Then
Response.Redirect NewURL & "?" & NoCacheURL()
Response.End
Else
Response.Redirect NEWURL & "&" & NoCacheURL()
Response.End
End If
End If
'
End Function
and NoCacheURL looks like this:

Function NoCacheURL()
'
On Error Resume Next
'
Randomize
' Randomize not needed if you use Now()
'
NoCacheURL = "NoCache=" & Server.URLEncode(rnd)
'
' or NoCacheURL = "NoCache=" & Server.URLEncode(Now())
' per Bill
'
End Function

时间: 2025-01-20 11:37:54

在ASP中不缓存页面的相关文章

Asp中代码与页面的分离

页面 为了避免ASP程序和HTML代码混写造成维护困难的情况,本文介绍了一种方法,利用模板来分离程序和页面,使程序设计更加轻松. 在使用ASP制作一个站点的时候,常常会出现一个ASP文件中,程序代码和HTML代码混合的情况.这样子做有许多缺点: 1. 且不说编程时就要对页面布局进行设计和编排,造成代码混乱难懂,不规范: 2. 当需要改变页面外观时,你不仅要改变HTML部份,也需要改变ASP代码,不易维护. 那么,要如何才能避免这些麻烦呢? 答案就是使用模板文件,将ASP代码和HTML页面分开,一

探讨:关于Asp中代码与页面的分离

页面 为了避免ASP程序和HTML代码混写造成维护困难的情况,本文介绍了一种方法,利用模板来分离程序和页面,使程序设计更加轻松.在使用ASP制作一个站点的时候,常常会出现一个ASP文件中,程序代码和HTML代码混合的情况.这样子做有许多缺点:1.且不说编程时就要对页面布局进行设计和编排,造成代码混乱难懂,不规范:2.当需要改变页面外观时,你不仅要改变HTML部份,也需要改变ASP代码,不易维护.那么,要如何才能避免这些麻烦呢?答案就是使用模板文件,将ASP代码和HTML页面分开,一切问题就都解决

ASP中生成静态页面技术

<!--#include file="conn.asp"--><%dim strfunction menu(id)set rs=server.CreateObject("adodb.recordset")sql="select * from menu where id1="&id&" order by url,id"rs.open sql,conn,1,1str=str+"<t

ASP.NET中清除缓存(禁止页面缓存)

在asp.net中使用模式dialog时,你会发现每次打开的页面都是相同的内容,页面内容并没有刷新,这是缓存的原因造成的, 解决方法如下: 第一种是ASP.NET清除页面缓存  代码如下 复制代码 Response.Buffer = true; Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1); Response.Expires = 0; Response.CacheControl = "no-cache"; R

ASP.NET 4中的可扩展输出缓存(可以缓存页面/控件等)_实用技巧

输出缓存的前世今生 ASP.NET 1.0引入输出缓存的概念,这使得开发者可以缓存页面.控件.控制器以及HTTP响应的输出到内存中.在后续的Web请求,ASP.NET就可以使用缓存中的内容更快响应. ASP.NET的输出缓存系统足够灵活,使得我们可以根据不同的查询字符串或者表单post参数来缓存不同版本的内容.例如test.aspx?category=Vegerable 和 test.aspx?category.aspx?category=Meat.它也允许我们根据浏览器类型或者用户语言偏好来缓

ASP.NET中如何对页面输出缓存

  最简单的缓存机制,把整个Aspx页面保存在服务器端内存中,用户请求页面时,直接从服务器端内存中提取数数据,不在经历页面的生命周期.主要用于不经常更新和修改,而在第一次编译是时要经过大量处理的数据.页面输出缓存是缓存的整个页面.     使用很简单<%@ OutPutCache Duration="60" VaryByParam="none"%>     Duration:缓存时间     VaryByParam:通过参数来更新缓存的内容     还有

ASP.NET 2.0中实现跨页面提交

asp.net|页面 在ASP.NET 1.X 版本中,页面都是提交到自己本身,并不能方便的指定需要提交的目的页面.例如FirstPage.aspx中的button只能提交到FirstPage.aspx,而不能提交到SecondPage.aspx.很多时候,ASP.NET 1.X这样工作方式使我们的开发方式受到不少限制.熟悉ASP/JSP/PHP的朋友大概很不习惯,因为以前经常使用的提交方式突然无法使用,虽然也有解决这个问题的方法(演示Webcast),可是过程太烦琐,不甚方便.令我们高兴的是,

ASP.NET 2.0 正式版中无刷新页面的开发(示例代码的补充)

asp.net|示例|刷新|无刷新|页面 原文请见Leon.Zhou的:http://pfzhou.cnblogs.com/archive/2006/03/31/363342.html 下载了示例代码,并转换成VB了,AJAX功能测试成功.但遇到些小问题:Demo1很正常.Demo2按Leon原来的写法testAJAX.aspx.vb中Line 22不成功.所以我直接在IDE环境中,修改button3的OnClientClick属性,见testAJAX.asp的Line 52.测试成功.Demo

在ASP中执行多个页面的表单提交

假设现在你要在站点上建立一个多页面的订货表单,从而执行从站点通过email发给订单书写人,并假定这些单独的页面.页面的个数以及页面上的输入域都可以根据实际要订购的产品而改变. 如果我们将每个页面都分别提交给FrontPage的 email 向导或CGI 的email 程序,那么可怜的订单书写人就要为订单的每一页都收到一个单独的邮件信息.当然我们可以通过session变量.隐藏域或查询字符串将订货数据从一页传递到另一页,但是在内存中储存这些数据会造成应用程序不平衡,另外潜在地需要大量的脚本.而且当