简体   繁体   中英

Prevent Image Caching in MVC 2 C#

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.

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM