在 asp.net 中为图像生成 etag?

发布于 2024-12-12 03:41:05 字数 561 浏览 5 评论 0原文

在我的网站上,用户可以上传公开显示的图像。当用户上传新图像时,它会覆盖旧图像之一。

因为图像可能很大,所以我希望将它们缓存起来。但是,当用户上传新图像时,不应使用旧的缓存图像。

动态图像的来源如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2024-12-19 03:41:05

在我看来,你应该能够这样做,例如:

Response.AddHeader("ETag","\"" + Guid.NewGuid().ToString() + "\"");

ETags 必须包含在 "

NOTE 内,显然,一旦 ETag 与图像一起返回,它就需要是我上面的代码只是一个概念证明:

是的,刚刚使用 Firebug 进行了测试并确认响应标头确实包含我创建的 Guid。

Looks to me that you should be able to do, for example:

Response.AddHeader("ETag","\"" + Guid.NewGuid().ToString() + "\"");

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文