Prevent Image Caching in MVC 2 C#

1.8k views Asked by At

I have a profile image upload page, where users can overwrite their previous profile picture.

But when I return the users to their profile page the browser has cached their previous image and only an F5 refresh returns the new image.

Is it possible to prevent the browser from caching the image, as some users might think their new upload failed.

Ideally I would want to only prevent the image from being cached. But a quick look at donut-caching seems to suggest its not possible to do in MVC2...??

Thanks for any pointers.

1

There are 1 answers

1
Anton Gogolev On BEST ANSWER

Preventing caching is a very bad idea. Rather, consider using technique with explicit "version":

http://www.example.com/users/johndoe/avatar.jpg?43567

Just increment this number every time an avatar is saved and you're good to go. Or, instead of having an explicit version, you can use value of UpdatedOn date/time column (if you have one) converted to ToFileTime().