Last post Mar 18, 2012 04:12 PM by hanzdolo
Nov 16, 2006 08:39 PM|xr280xr|LINK
I've read tons of forum posts on how to prevent caching of webforms and images on those forms and almost every post has a different solution. What's worse is I haven't yet found one that works.
I have a photo upload page that lets users upload AND make changes to uploaded jpegs. When an update is made, the image is changed but it keeps the same filename. So in IE and probably firefox, it caches the old images and you have to hit refresh to see
the changes. Aside from obviously not being user friendly, the problem is it tries to re-execute the last postback event when you hit refresh.
So, can someone tell me the correct, tried and true way, to prevent either the caching of the entire form, or at least the images on the form? Thanks!
Nov 17, 2006 09:34 PM|xr280xr|LINK
I've tried setting cacheability, pragma, response.exires, META HTTP-EQUIV="Expires"...nothing works.
Nov 17, 2006 10:28 PM|pkellner|LINK
Nov 17, 2006 10:31 PM|pkellner|LINK
meanwhile, try this:
sounds like the browser is caching your image.
Peter B's got a good article on caching in general.
For preventing pages from being cached downstream (for example with a logout page) in ASP.NET, you can set the "no-cache" header by using the HttpCachePolicy.SetNoStore method. Put this in your page_load at the latest. You can also set this in your
page's HEAD section by adding the following line of code:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
Apr 16, 2007 07:58 AM|shur2007|LINK
to make long story short: modify the src attribute for your image tag with random parameter like:
<img src='mypicture.png?jopa=12345' />
where 12345 should be unique. i use hour+min+sec
good luck [cool]
Oct 31, 2007 09:19 PM|xr280xr|LINK
Adding a query string to the image URL would prevent the problematic effects of browser caching but it doesn't actually stop the image from being cached. I have still not found a solution to prevent the browser from caching images. What I ended up doing
on my last project, which dynamically drew a bar graph, was to name the image with a GUID appended to it (same idea sas the query string approach). That way as the graph updates it won't have a picture with the same name cached to load. But if I go into my
browser's cache folder, I'll see a few hundred graph bitmaps saved there.
Nov 02, 2007 03:24 PM|anas|LINK
add this to your page_load , this will prevent the page caching on teh client
Nov 05, 2007 10:35 AM|abhishekbhosale|LINK
Mar 18, 2012 04:12 PM|hanzdolo|LINK
Thank you because That was the only solution that worked for me. I've tried everything else. I wrote an Image editor where my client can edit his thumbnails and position the artwork on the apparel and the browser kept caching the images so he couldn't see
the changes he made. The addition of a simple '~.ImageUrl="foo.png?ID="+DateTime.Now' worked perfectly