Banshee
Banshee

Reputation: 15807

Handle cached images? How to get the browser to show the new version?

Hi,

When a webpage with a image(img_01.jpg) is loaded the image will be cached by the browser. Say that we update img_01.jpg and saves it with the same name, when visiting the same page the old image will be shown from the cache.

How should I handle this in ASP.NET MVC?

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

BestRegards

Upvotes: 1

Views: 1543

Answers (3)

user2168730
user2168730

Reputation: 9

In C# when u r binding Image control just make the url as query string. Ex:-

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

Browser will always see it as new request and it will not take image from CACHE.

Upvotes: 0

Banshee
Banshee

Reputation: 15807

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

Upvotes: 0

Vladimir Mischenko
Vladimir Mischenko

Reputation: 320

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

Upvotes: 1

Related Questions