I have been trying to find a way to prevent the images on my site from being
cached on the user's machine. I want to avoid this because the images used
in an Image control often change, yet have the same name. When they are
cached, the cached image is displayed which is not what I want. I thought
that using
Response.Cache.SetCacheability(HttpCacheability.No Cache)
would have achieved this, but it seems to only prevent the .aspx file from
being cached. Is there any way to prevent images from being cached as well?
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/ 7 1948
Nathan,
I am not sure if this will do it (I did not try it). In this sample I make
the image in the procedure, however you can do it of course using a read.
Now you can get the image by its page url
\\\
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,
Cor
I don't think it is caching. Check that the new image on the server has a
later create date than the older, if not the older will be shown.
Test this by having 2 images, aaa.jpg, put the one with the older creation
date on the server and browse to it, now put the newer one on the server,
browse to it and the 2nd one will show, all OK.
Now rename them to bbb.jpg, first put the one with the newer creation date
on the server, browse, now the older creation date, browse, the 1st image
still shows up.
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:#Q**************@TK2MSFTNGP15.phx.gbl... I have been trying to find a way to prevent the images on my site from
being cached on the user's machine. I want to avoid this because the images used in an Image control often change, yet have the same name. When they are cached, the cached image is displayed which is not what I want. I thought that using Response.Cache.SetCacheability(HttpCacheability.No Cache)
would have achieved this, but it seems to only prevent the .aspx file from being cached. Is there any way to prevent images from being cached as
well? -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
I agree with Chris - but if you want to make sure this doesn't happen, use a
HTTPHandler to draw your own images - then they can't steal your bandwidth
either ;-) http://www.uberasp.net/GetArticle.aspx?id=13
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eE**************@TK2MSFTNGP14.phx.gbl... Nathan,
I am not sure if this will do it (I did not try it). In this sample I make the image in the procedure, however you can do it of course using a read. Now you can get the image by its page url
\\\ 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,
Cor
Well what you can also do is when generating the URL for the image,
append a random string to it like this:
image.ImageUrl = "someimage.gif?randomstring"
and then the browser will get the fresh image as long as the
randomstring is different. For random string you can use TickCount or
anything else you want. Of course there are some drawbacks to this
technique (such as brwoser getting image even though it hasn't changed).
L
Chris Botha wrote: I don't think it is caching.
Think again. If an image is being cached on the client-side or some
downstream proxy, you can change it on the server-side all day long
without affecting the client.
You *must* specify the appropriate Cache-Control header
("must-revalidate" in theory, thanks to IE "no-cache" in practice) to
force clients and proxies to send conditional GETs and pick up
server-side updates.
Cheers,
-- http://www.joergjooss.de
mailto:ne********@joergjooss.de
You can configure this in IIS MMC by navigating to the folder containing the
images and adjusting the HTTP Headers to either "expire immediately" or
"never expire".
--
Benjamin Strackany http://www.developmentnow.com
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... I have been trying to find a way to prevent the images on my site from
being cached on the user's machine. I want to avoid this because the images used in an Image control often change, yet have the same name. When they are cached, the cached image is displayed which is not what I want. I thought that using Response.Cache.SetCacheability(HttpCacheability.No Cache)
would have achieved this, but it seems to only prevent the .aspx file from being cached. Is there any way to prevent images from being cached as
well? -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
Bill, I agree with Chris - but if you want to make sure this doesn't happen, use a HTTPHandler to draw your own images - then they can't steal your bandwidth either ;-)
I had the idea that that is what I am doing in my sample
:-)
The bitmap is embedded in the url by the and sent as bitmap by the redirect.
It is not a reference to an image url.
However if you disagree that with me, please tell where I make a mistake in
that idea?
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fred |
last post by:
Hello
As mentioned in another post, I'm in the process of extending an existing
class.
One of the things I'm trying to achieve is an improvement in performance
through the use of some image...
|
by: Marwin |
last post by:
Hi all,
I have a database with 40GB of binary objects stored in image columns
in two tables.
Our database server is also used for another 15 databases.
SQL Server caches the image-column,...
|
by: Mike Sobeiski |
last post by:
Hi There!
I'm developing a web project that requires to produce charts off the
database and output it as image and presented to the user in a HTML
document. (NOTE: Image is not directly...
|
by: Suraj Joneja |
last post by:
Hi All,
I've an image control on my ASP.net page. This displays an image named
'Logo.jpg' in the location '~\Images'. Another application can change this
image. It can select any image and...
|
by: Jake |
last post by:
Does cookieless session state (with the sessionid embedded into the url)
interfere with the browser's retrieval of cached images from one session to
the next? Does the sessionid embedded into the...
|
by: Nathan Sokalski |
last post by:
I have been trying to find a way to prevent the images on my site from being
cached on the user's machine. I want to avoid this because the images used
in an Image control often change, yet have...
|
by: Giggle Girl |
last post by:
Hello,
I am helping to design a web application that uses 167 little icons on
various pages in a framed environment. As is, the app loads each icon
on a page by page basis, and if an image...
|
by: Mark Denardo |
last post by:
This is related to another post I submitted, but I'll be more precise this
time.
I have a web page that contains an Image webcontrol that loads its image by:
Image1.ImageUrl="<username>.jpg",...
|
by: vunet.us |
last post by:
Hi,
I found a bug in IE6, though it is known already. If I have a CSS
background property set to some image, such as
background:url(myimg.gif);, and I apply this property to some html
element,...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |