Image control CACHING IMAGE

S

Suraj Joneja

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 upload to the folder 'Images' and newly
selected image would overwrite existing image 'Logo.jpg'. (Image name
remains same and image changes). The image control on my page doesn't
refresh the newly selected image. it displays the old image where as the
file in the imageUrl is different. I want the image control to
"refresh/reload"
How do I solve this issue????

Thanks
 
D

DalePres

Are you sure the problem isn't that the original page is being cached and
therefore the browser isn't seeing the new image URL? Checkout caching of
ASP.Net pages on MSDN.

DalePres
MCAD, MCDBA, MCSE
 
J

Joerg Jooss

Suraj said:
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 upload to the folder 'Images'
and newly selected image would overwrite existing image 'Logo.jpg'.
(Image name remains same and image changes). The image control on my
page doesn't refresh the newly selected image. it displays the old
image where as the file in the imageUrl is different. I want the
image control to "refresh/reload"
How do I solve this issue????

As the other poster has already pointed out, this is probably not a bug
in your code, as a simple debugging session in VS.NET should point out.

You have to make sure HTTP caches revalidate that your logo is up to
date. You should set a Cache-Control: no-cache header for your "Images"
folder using IIS's admin applet.

Cheers,
 
E

Eliyahu Goldin

You can trick browser into refreshing the image if you add a random number
query parameter to the image url. You can use a timestamp as the parameter.

imageUrl="/Images/Logo.jpg?"+<something random>

Eliyahu
 
J

Joerg Jooss

Eliyahu said:
You can trick browser into refreshing the image if you add a random
number query parameter to the image url. You can use a timestamp as
the parameter.

imageUrl="/Images/Logo.jpg?"+<something random>

But this defeats caches as well, which is not what you want most of the
time -- caches should just send a conditional GET to make sure they
won't serve a stale image file.

It's a trade-off -- either users begind pure HTTP 1.0 caching proxies
see old logos, or the server is hit each and every time to fetch the
logo.

Cheers,
 
S

Suraj Joneja

Thank you Joerg,

Setting the no-caching header worked just fine!

thanks all
Suraj
 
E

Eliyahu Goldin

It depends on the scenario. If the requested resource changes only
occasionally, it may pay to care of caching. If every time the resource has
another content, ignoring caching is fine.

Eliyahu
 

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

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top