Handle cached images? How do I force the browser to show the new version?

Hello,

When a web page with an image (img_01.jpg) is loaded, the image will be cached by the browser. Let's say we update img_01.jpg and save it with the same name, when visiting the same page from the cache, the old image will be shown.

How should I handle this in ASP.NET MVC?

I know that in regular ASP.NET (no MVC) an additional component needed to be created and that component would add a random number to the end of the filename. How do I do this in ASP.NET MVC?

BestRegards

+1


source to share


3 answers


I decided to use the version number of the main object in the image file name, this will make sure that the end user always sees the correct image.



0


source


You can use HTTP image handlers to add expiration headers. But it mostly depends on the browser if the expiration headers are used correctly. Does it help?



+1


source


In C # when ur binding Image control just turns url into query string. Example: -

string  _urlPhoto = "UploadPhoto" + "/" + Imagename + "?" + Guid.NewGuid().ToString();

      

The browser will always treat it as a new request and will not accept an image from CACHE.

0


source







All Articles