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!
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:
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.
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
xr280xr
Member
413 Points
289 Posts
Prevent Caching Correctly?
Nov 16, 2006 07:39 PM|LINK
Hi,
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!
Cache ASP.NET cache
xr280xr
Member
413 Points
289 Posts
Re: Prevent Caching Correctly?
Nov 17, 2006 08:34 PM|LINK
Anyone?
I've tried setting cacheability, pragma, response.exires, META HTTP-EQUIV="Expires"...nothing works.
pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: Prevent Caching Correctly?
Nov 17, 2006 09:28 PM|LINK
http://peterkellner.net
Microsoft MVP • ASPInsider
pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: Prevent Caching Correctly?
Nov 17, 2006 09:31 PM|LINK
meanwhile, try this:
sounds like the browser is caching your image.
Peter B's got a good article on caching in general.
http://www.eggheadcafe.com/articles/20060407.asp
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">
http://peterkellner.net
Microsoft MVP • ASPInsider
shur2007
Member
2 Points
1 Post
Re: Prevent Caching Correctly?
Apr 16, 2007 06:58 AM|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]
xr280xr
Member
413 Points
289 Posts
Re: Prevent Caching Correctly?
Oct 31, 2007 08:19 PM|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.
anas
All-Star
73649 Points
7914 Posts
Moderator
Re: Prevent Caching Correctly?
Nov 02, 2007 02:24 PM|LINK
hi
add this to your page_load , this will prevent the page caching on teh client
Response.Cache.SetCacheability(HttpCacheability.NoCache)
abhishekbhos...
Member
130 Points
43 Posts
Re: Prevent Caching Correctly?
Nov 05, 2007 09:35 AM|LINK
Response.cache.setslidingExpiration(true);
hanzdolo
Member
18 Points
11 Posts
Re: Prevent Caching Correctly?
Mar 18, 2012 03:12 PM|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