生成在asp.net图像ETag的? [英] Generating etags for images in asp.net?

查看:70
本文介绍了生成在asp.net图像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

所以,我可以注入到标题中的ashx的文件的响应,如果我需要。

So I can inject headers into the response in the .ashx file if I need to.

我已经告诉来使用ETag用于此目的,但我不知道如何在asp.net做到这一点。在的.js 的.css 我的网站上的文件已经有ETag的,但我不知道什么是他们产生。此外,任何内置系统生成的ETag大概不会明白我.ashx的文件是如何工作的。

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.

我如何为我的网站ETag的,并让这个他们的工作,因为他们咋办?

How do I generate etags for my site, and make it so that they work as they are supposed to?

推荐答案

在我看来,你应该能够做到的,例如:

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

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

的ETag必须在

注意显然,一旦一个ETag返回与它需要在后续请求相同的图像。上面我的code只是一个概念证明。 :)

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

编辑:是的,只是测试和使用Firebug的响应头确实包含了我创建的GUID证实

Yep, just tested and confirmed using Firebug that the Response headers do contain the Guid that I created.

这篇关于生成在asp.net图像ETag的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆