want to Avoid image cacheing in ASP.NET Pages

V

visu

I am currently working on my personl website a completely DB driven
web application. in that i ve updating the images thru my admin
panel .. but i am getting the old images not the update one when see
the pages in the front . when i explicitly right click and select
refresh button or hit F5 ,then my pages are loaded with new images..
why this kind of effect is happening. how to avoid the caching of
images in both the server side(page cache) and client side? can anyone
help me to solve this problem. i am accessing the admin module and the
pages in a same computer.

Regards.
Visu
 
V

visu

The easiest (and certainly not the only) way to ensure that the browser does
not cache images is to suffix the image url with a unique querystring item,
like so:

"http://mysite/images/image001.jpg?id="+DateTime.Now.Ticks.ToString()

Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net






- Show quoted text -

thats great idea but now only i ve noticed that all my pages are get
cached in the browser.. how to avoid caching in the browser.. i ve
tried meta tags and setting header parameter to escape caching of
pages.. but no use .. give me handy solution to this problem.

Regards
visu
 
J

Joerg Jooss

Thus wrote Visu,
I am currently working on my personl website a completely DB driven
web application. in that i ve updating the images thru my admin panel
.. but i am getting the old images not the update one when see the
pages in the front . when i explicitly right click and select
refresh button or hit F5 ,then my pages are loaded with new images..
why this kind of effect is happening. how to avoid the caching of
images in both the server side(page cache) and client side? can anyone
help me to solve this problem. i am accessing the admin module and the
pages in a same computer.

1) If you serve your images as static content through IIS:
Put all images in a common folder and set a HTTP Cache-Control header for
this folder in IIS manager, e.g.
Cache-Control: no-cache (-> never use a cached copy without revalidation)
or
Cache-Control: max-age=43200 (-> allow public caching for 12 hours [43200
seconds] at most)

2) If you serve your images as dynamic content through ASP.NET, e.g.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
or
Response.Cache.SetMaxAge(TimeSpan.FromHours(12.0));

Note that unless you're updating your images at an astounding pace, marking
them non-cacheable is hardly advisable ;-)

Cheers,
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top