在 ASP.NET 中发送压缩响应
我正在 IIS6 上为 ASP.NET 应用程序运行一个网站,并启用了压缩,这对于 .aspx 网页效果很好。
不起作用的是下载的二进制文件,这些文件作为回发响应的一部分传输:例如链接按钮是“下载到 Excel” - 用户单击,代码生成一个二进制文件,执行 Response.Clear(),然后写入文件到 Response.OutputStream。
浏览器可以看到响应,但它始终为零字节。 因此,我假设网络浏览器期望压缩响应,并且由于原始二进制文件不是有效的压缩流,因此它会失败。 我很困惑如果我已经清除了响应,为什么会出现这种情况 - 当然响应标头(指定压缩)也被清除了?
因此出现了两个问题:
1)如何压缩二进制文件以发送压缩响应? 2)如何在运行时检查IIS压缩是否启用?
干杯
I am running a website on IIS6 for ASP.NET application and enabled compression, which worked fine for the .aspx web pages.
What isn't working is downloaded binary files that are transmitted as part of a postback response: e.g. link button is 'download to excel' - user clicks and the code generates a binary file, does a Response.Clear() and then writes the file to the Response.OutputStream.
A response is seen by browsers but it is always zero bytes. I assume therefore that web browsers are expecting a compressed response, and as the raw binary isn't a valid compressed stream it fails. I'm puzzled as to why this should be if I've cleared the response - surely the response headers (specifying compression) are also cleared?
So two questions arise:
1) how do I compress the binary file to send a compressed response?
2) how can I check at runtime to see if IIS compression is enabled?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会禁用压缩并检查这是否仍然有效,只是为了隔离这确实是由于 IIS 压缩造成的。 我告诉你,因为我正在运行一个启用 IIS/压缩的网站,它可以毫无问题地提供 PDF 文件(二进制)。
无论如何,这是对我有用的代码部分。
I would disable compression and check whether this still works, just to isolate the fact that this is indeed due to IIS compression. I'm telling you that 'cos I'm running a IIS/Compression enabled site which provides PDF files (binary) without a problem.
Anyway here's the part of code which works for me.