ASP Snippets

Categories






Alerts

Free Alerts

Your email will always be
private and will not be shared.




Follow us on twitter.




Zoom In | Zoom Out


Author is awarded Most Valuable Professional award by Microsoft ASP/ASP.Net

Issue: Images with same name or URL do not get updated when file is changed in ASP.Net

Author:Mudassar Khan

Here I am explaining the issue when two images have same name and URL, thus even if the image is replaced the browser still displays the old image in spite of page reload and page refresh.

 

Cause

Since the images have same name and URL browser picks the image from the cache and displays the same for faster loading of the pages. Thus even if you change the image server side the same cached image is displayed until you clear the cache of the browser.

 

Solution

Now since it is not possible to clear cache of user’s browser from server side. We can use the following trick

C#

Image1.ImageUrl = "~/images/myImage.jpg?" + DateTime.Now.Ticks.ToString();

 

VB.Net

Image1.ImageUrl = "~/images/myImage.jpg?" + DateTime.Now.Ticks.ToString()

 

The idea is to append some data to the image URL so that the URL becomes unique. When the URL is unique the browser will always download the file from the server instead of loading it from cache

The following figure displays the page source which describes the output URL of the image highlighted




That’s it. Hope you liked it.

Posted: Sep 30 2009, 18:03 by Mudassar Khan | Comments (1) RSS comment feed |
Views: 1918
Page copy protected against web site content infringement by Copyscape


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share





Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading




0  +  0  =   










Community News





Web Hosting SpotLight


Consulting


For consulting and work related queries click here.



Advertise


Advertise with us. For more details click here.


Suggestions


Please provide your valuable suggesstions here.

This Site is hosted on

Lunarpages.com Web Hosting