加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Response.Flush()抛出System.Web.HttpException

发布时间:2020-12-15 17:36:32 所属栏目:百科 来源:网络整理
导读:我有一个HttpHandler,我用来处理客户网站上的某些图像.当我将图像流输出到响应对象时,偶尔会调用Flush会抛出错误.这是一个代码块 var image = Image.FromStream(memStream);if (size -1) image = ImageResize.ResizeImage(image,size,false);if (height -1)
我有一个HttpHandler,我用来处理客户网站上的某些图像.当我将图像流输出到响应对象时,偶尔会调用Flush会抛出错误.这是一个代码块
var image = Image.FromStream(memStream);
if (size > -1) image = ImageResize.ResizeImage(image,size,false);
if (height > -1) image = ImageResize.Crop(image,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:TeamCitybuildAgentwork79b3c57a060ff42dsrcPineBluff.CoreImageHandler.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行.

在执行flush之前,是否有一种检查方法,而不会将其包装在try / catch块中.

解决方法

虽然我同意 Mitchel – 如果您在其他地方使用此功能,您可以先尝试致电 Response.IsClientConnnected.

Gets a value indicating whether the client is still connected to the server.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读