By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

Caching in IE

P: n/a
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.No Cache)

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?

Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Clear

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

Response.Cache.SetExpires(DateTime.Now.AddTicks(50 0))

I hope this helps,

Cor
Jul 21 '05 #2

P: n/a
This seems to not cach the page but it still appears to be caching the images
on the page.

"Cor Ligthert" wrote:
Clear

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

Response.Cache.SetExpires(DateTime.Now.AddTicks(50 0))

I hope this helps,

Cor

Jul 21 '05 #3

P: n/a
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(50 0))
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
Jul 21 '05 #4

P: n/a
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
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.