我有一个HttpHandler,我用它来处理客户端网站上的某些图像。当我将图像流输出到响应对象并偶尔调用Flush时,会引发错误。这里是一个代码块Response.Flush()抛出System.Web.HttpException
var image = Image.FromStream(memStream);
if (size > -1) image = ImageResize.ResizeImage(image, size, size, false);
if (height > -1) image = ImageResize.Crop(image, size, height, ImageResize.AnchorPosition.Center);
context.Response.Clear();
context.Response.ContentType = contentType;
context.Response.BufferOutput = true;
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
context.Response.Flush();
context.Response.End();
从我读过的东西,这个异常是由客户端断开导致进程完成之前并没有什么刷新。
这是我的错误页面的输出
System.Web.HttpException: An error occurred while communicating with the remote host. The error code is 0x80070057.
Generated: Mon, 12 Oct 2009 03:18:24 GMT
System.Web.HttpException: An error occurred while communicating with the remote host. The error code is 0x80070057.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)
at System.Web.Hosting.ISAPIWorkerRequest.FlushResponse(Boolean finalFlush)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.Flush()
at PineBluff.Core.ImageHandler.ProcessRequest(HttpContext context) in c:\TeamCity\buildAgent\work\79b3c57a060ff42d\src\PineBluff.Core\ImageHandler.cs:line 75
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
context.Response.Flush落在线75
有没有办法进行刷新之前,要检查这个没有尝试它包裹/ catch块。?
所以,我可以换我的.Flush()和.END()在.IsClientConnected并有修复我的问题,你觉得呢?客户的客户没有收到他们屏幕上的错误,我每次只收到ELMAH的电子邮件。只是一个小小的烦恼比什么都重要。 – 2009-10-12 18:42:43
你肯定可以将.Flush包裹在检查中 - 不太确定是否存在任何未调用的影响。结束......我认为在那里有一些长时间运行的进程会导致人们在完成图像生成之前断开连接。 – 2009-10-12 20:58:33
我可以确认在.IsClientConnected内包装flush可以抛出相同的异常;现在发生在我身上。坚持.End() – Contra 2011-06-28 09:02:40