Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Asp.net 2.0 caching and images

Reply
Thread Tools

Asp.net 2.0 caching and images

 
 
Alex Greenberg
Guest
Posts: n/a
 
      01-13-2006
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.

 
Reply With Quote
 
 
 
 
S. Justin Gengo [MCP]
Guest
Posts: n/a
 
      01-13-2006
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

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Alex Greenberg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.
>



 
Reply With Quote
 
 
 
 
Joerg Jooss
Guest
Posts: n/a
 
      01-16-2006
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,
--
Joerg Jooss
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
Alex Greenberg
Guest
Posts: n/a
 
      01-18-2006
Thanks, I don't have control over the second approach, but the first
one worked perfectly.

Best,

Alex

 
Reply With Quote
 
grubar30 grubar30 is offline
Junior Member
Join Date: Mar 2008
Posts: 1
 
      03-10-2008
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!!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable page caching without disabling caching of jpegs andstylesheets etc JimLad ASP .Net 3 01-21-2010 10:13 AM
Caching js and images on client Smokey Grindle ASP .Net 1 07-07-2006 10:05 PM
Fragment Caching inside page caching? Troy Simpson ASP .Net 0 01-19-2004 11:57 AM
onLoad event and pre caching images Stuart Javascript 0 11-16-2003 05:08 PM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments