防止 MVC 2 C# 中的图像缓存
我有一个个人资料图片上传页面,用户可以在其中覆盖他们以前的个人资料图片。
但是,当我将用户返回到他们的个人资料页面时,浏览器已缓存了他们以前的图像,并且只有 F5 刷新才会返回新图像。
是否可以阻止浏览器缓存图像,因为某些用户可能认为他们的新上传失败。
理想情况下,我只想防止缓存图像。但快速浏览一下甜甜圈缓存似乎表明它在 MVC2 中不可能做到......?
感谢您的指点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
防止缓存是一个非常糟糕的主意。相反,请考虑使用具有明确“版本”的技术:
只需在每次保存头像时增加此数字即可。或者,您可以使用转换为
ToFileTime()
的UpdatedOn
日期/时间列(如果有)的值,而不是使用显式版本。Preventing caching is a very bad idea. Rather, consider using technique with explicit "version":
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 toToFileTime()
.