如何仅对一个处理程序 .ashx 禁用 gzip
我正在使用 IIS6 运行一个网站,我编写了一个简单的通用处理程序,当它接收图像 url 作为查询字符串时,它返回较小的图像。我的问题是服务器正在将 gzip 应用于某些文件类型,例如 .aspx 和 .ashx。
这使得处理程序的响应图像质量较低,因为它们被压缩了。
我如何才能仅针对此处理程序文件禁用 gzip,我希望找到一个无需编辑 IIS 的解决方案。
这可能吗?
I am running a website using IIS6 and i wrote a simple generic handler which return smaller images when it receive image url as query string. My problem is that the server is applying gzip to some file types such as .aspx and .ashx.
And that made my response image from the handler appear with lower quality because they are compressed.
How can i disable gzip for just this handler file, i hope for a solution without editing the IIS.
Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用 - 在 ProcessRequest 方法中:
我假设这使 IIS 认为客户端不支持 GZip (或其他压缩方法),因此发送未压缩的响应。
是的 - 这是一个黑客(通常你不应该弄乱请求标头),但它是迄今为止我见过的最简单的解决方案。
我个人需要这个,因为对 Ajax 调用的简单 5 字符纯文本响应在 GZip“压缩”后最终长度为 124 字节。
这回答了这个问题的标题。然而,对于您的图像场景 - 它实际上不应该有任何区别,因为 GZip 是无损的(未压缩数据=原始数据)。
This worked for me - in the ProcessRequest method:
I assume that this makes IIS think that the client does not support GZip (or other compression methods) and therefore sends the response uncompressed.
Yes - it is a hack (generally you should not mess with the request headers) but it is by far the simplest solution I have seen.
I personally needed this because a simple 5 character plain text response to an Ajax call ended up being 124 bytes long after GZip "compression".
This answers the title of this question. However for your scenario with images - it really shouldn't make any difference as GZip is lossless (uncompressed data = original).
这个SO答案似乎与您的场景几乎完全相同。
答案是此链接 讨论如何做基于/关闭压缩场景的文件夹。
还有此链接在附近讨论了这个问题文章底部。
您应该能够通过自己编辑元数据库或通过 adutils.vbs 来完成此操作。
This SO answer seems to be almost exactly the same as your scenario.
In the answer is this link discussing how to do a folder based on/off compression scenario.
There is also this link that discusses this near the bottom of the article.
You should be able to do it by editing the metabase yourself or via adutils.vbs.