在 asp.net 中为图像生成 etag?
在我的网站上,用户可以上传公开显示的图像。当用户上传新图像时,它会覆盖旧图像之一。
因为图像可能很大,所以我希望将它们缓存起来。但是,当用户上传新图像时,不应使用旧的缓存图像。
动态图像的来源如下所示:
userImage.ashx?id=f488b864-0a0b-46d9-af4a-a43cd0dcf751&type=micrositePhoto
因此,如果需要,我可以将标头注入 .ashx 文件中的响应中。
我被告知为此目的使用 etag,但我不这样做不知道如何在 ASP.NET 中执行此操作。我网站上的 .js
和 .css
文件已经有 etag,但我不知道是什么生成了它们。此外,任何生成 etag 的内置系统可能无法理解我的 .ashx 文件的工作原理。
如何为我的网站生成 etag,并使其按预期工作?
On my site, users can upload images that are displayed publicly. When the user uploads a new image, it overwrites one of their old images.
Because the images can be large, I want them to be cached. However, when the user uploads a new image, the old cached images should not be used.
The source of the dynamic images looks like this:
userImage.ashx?id=f488b864-0a0b-46d9-af4a-a43cd0dcf751&type=micrositePhoto
So I can inject headers into the response in the .ashx file if I need to.
I've been told to use etags for this purpose, but I don't know how to do this in asp.net. The .js
and .css
files on my site already have etags, but I don't know what is generating them. Also, any in-built systems to generate etags will probably not understand how my .ashx file works.
How do I generate etags for my site, and make it so that they work as they are supposed to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,你应该能够这样做,例如:
ETags 必须包含在
"
NOTE 内,显然,一旦 ETag 与图像一起返回,它就需要是我上面的代码只是一个概念证明:
是的,刚刚使用 Firebug 进行了测试并确认响应标头确实包含我创建的 Guid。
Looks to me that you should be able to do, for example:
ETags must be enclosed inside
"
NOTE Obviously, once an ETag is returned with an image it needs to be the same on subsequent requests. My code above was just a proof of concept. :)
Edit: Yep, just tested and confirmed using Firebug that the Response headers do contain the Guid that I created.