Caching in IE

G

Guest

I want to write code to prevent IE from caching my pages at certain times.
The following META tags prevent the page from caching but images still cache:

<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

I tried do it with asp.net but also found this only stoped pages from being
cached but not images:

Response.AppendHeader("Cache-Control", "no-cache")
Response.AppendHeader("Pragma", "no-cache")
Response.Cache.SetCacheability(HttpCacheability.NoCache)

The only thing I've found that has prevented images and pages from being
cached is setting HTTP Headers on IIS but I don't think I can turn this on
and off programatically. Does anyone have any ideas?
 
C

Cor Ligthert

Clear

Those did not work for me, while this one did.

Response.Cache.SetExpires(DateTime.Now.AddTicks(500))

I hope this helps,

Cor
 
C

Cor Ligthert

Clear,

I have used this in this sample, which creates every second an image,
however maybe you create them in another way, so have a look. (Not for
production use, I assume that it will be to slow on an internet connection).

\\\Form 1 Needs a imagebox on the page
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Image1.Height = New Unit(32)
Me.Image1.Width = New Unit(200)
Image1.Visible = True
Dim scriptString As String = "<script language=JavaScript>" & _
"setclock(); function setclock(){document.images.Image1.src = " & _
"'http://localhost/WebClock/WebForm2.aspx';setTimeout('setclock()',1000)}</script>"
Page.RegisterStartupScript("setclock", scriptString)
End Sub
///
\\\Form2 needs nothing
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Cache.SetExpires(DateTime.Now.AddTicks(500))
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
Dim textHeight As Single
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g.MeasureString(now.tostring, myFont)
g.DrawString(Now.ToString, myFont, myForeBrush, _
New RectangleF(0, 0, 120, 20))
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
bm.Save(ms, Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
g.dispose
End Sub
///
I hope this helps a little bit?

Cor
 
A

Andrew Morton

If you made your image URLs in the form thing.jpg?x where x is a different
string every time (e.g. the time) then you might have success. It should
look to IE as if it's meant to be getting the image from a CGI script, and
any other caching proxy server (terminology?) along the way should also not
cache it. The server should (I'm guessing there) ignore the ?x part as long
as it doesn't have some CGI process associated with .jpg.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top