“响应过滤器的无效使用”压缩来自 IHttpHandler 的响应时
我有一个 IHttpHandler 返回一个文件。当响应流被压缩时,无论是自动使用 Telerik RadCompression 还是通过使用
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
返回到浏览器的响应显式设置过滤器都是正确的,但响应末尾是一些 HTML。 HTML 包含异常:
[HttpException (0x80004005): Invalid use of response filter] System.Web.HttpResponseStreamFilterSink.VerifyState() +3928894 System.Web.HttpResponseStreamFilterSink.Write(Byte[] buffer, Int32 offset, Int32 count) +28 System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +363 System.IO.Stream.Close() +28 System.IO.Compression.GZipStream.Dispose(Boolean disposing) +63 System.IO.Stream.Close() +28 System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +595 System.IO.Stream.Close() +28 System.IO.Compression.GZipStream.Dispose(Boolean disposing) +63 System.IO.Stream.Close() +28 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +754 System.Web.HttpResponse.FilterOutput() +121 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +174
如果我确保响应未压缩,则响应不包含异常。
这是怎么回事?
I have an IHttpHandler returning a file. When the response stream is compressed, either automatically using Telerik RadCompression or by explicitly setting a filter using
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
the response returned to the browser is correct but at the end of the response is some HTML. The HTML contains the exception:
[HttpException (0x80004005): Invalid use of response filter] System.Web.HttpResponseStreamFilterSink.VerifyState() +3928894 System.Web.HttpResponseStreamFilterSink.Write(Byte[] buffer, Int32 offset, Int32 count) +28 System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +363 System.IO.Stream.Close() +28 System.IO.Compression.GZipStream.Dispose(Boolean disposing) +63 System.IO.Stream.Close() +28 System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +595 System.IO.Stream.Close() +28 System.IO.Compression.GZipStream.Dispose(Boolean disposing) +63 System.IO.Stream.Close() +28 System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +754 System.Web.HttpResponse.FilterOutput() +121 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +174
If I make sure the response is NOT compressed, the response contains no exception.
What's up with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您没有阻止缓冲。显然,要压缩响应,您必须允许对其进行缓冲。
即,需要删除以下两行之一:
Make sure you're not preventing buffering. Apparently, to compress the response, you have to allow it to be buffered.
I.e., one of the following two lines needs to be removed: