Asp.net 2.0 caching and images

A

Alex Greenberg

Hi,

I'm having a strange problem:

I have a product.aspx page where the admin can change product
properties, including the JPEG. The JPEG will always have the same
name: eg. 120.jpg and in the same location.

1) Admin visits page and browses to images/myimage.jpg
2) Application takes myimage.jpg and creates a modified copy in
myapp/img and calls it 120.jpg.
3) image path in database changes to myapp/img/120.jpg
3) Admin leaves page
4) Admin revisits page (in same session) and picks a different image,
which replaces the old one but retains the name 120.jpg.
5) Admin leaves and comes back one more time. OLD IMAGE IS STILL
DISPLAYED (from step 2). Even though image is changed on hard drive.

obviously, IE is caching the image and going back to it on subsequent
visits in same session. I tried using the No-Cache directive. I also
added a ?t=<random> to the page parameters. Neither of these worked.

Please help.
 
J

Joerg Jooss

Hello S. Justin Gengo [MCP],
Alex,

Try adding the t=<random>

To the image url instead of the page. IE caches images based on the
image path not the page path. Making it look like the image path has
changed will stop the caching. For example:

http://msdn.microsoft.com/asp.net/art/asprk.jpg?t=1234

A better approach is to use HTTP CacheControl headers. Simply configure IIS
to attach the HTTP header CacheControl: no-cache to all images served from
your image directory.

Cheers,
 
A

Alex Greenberg

Thanks, I don't have control over the second approach, but the first
one worked perfectly.

Best,

Alex
 
Joined
Mar 10, 2008
Messages
1
Reaction score
0
awesome man.....thank you so much for this tip....I've spent hours/days trying to work out why my images were being cached by IE, inspite of the fact that I tried all the usual no-cache code (both HTML meta and ASP)

you saved me dude....thank you heaps!!!!
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top