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.