问题描述
我有我使用来处理一个客户的网站特定的图像的HttpHandler。当我输出图像流响应对象,并调用Flush偶尔引发错误。这里是一个$ C $使用cblock
I have a HttpHandler that I'm using to handle certain images on a client's website. When I'm outputting the image stream to the response object and call Flush occasionally an error is thrown. Here is a codeblock
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();
从我读过,这个异常是由客户端断开导致进程已经完成,并没有什么刷新之前。
From what I've read, this exception is caused by a client disconnecting before the process has completed and there is nothing to flush.
这是我的错误页面的输出
Here is an output of my error page
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。
context.Response.Flush falls at line 75.
有没有办法不用在try / catch块包裹它在执行刷新之前进行检查。
Is there a way to check this before performing the flush without wrapping it in a try/catch block.?
推荐答案
虽然我与Mitchel - 有没有必要打电话给你即将通话结束,如果你使用这个别处冲洗,你可以尝试调用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.isclientconnected.aspx\"><$c$c>Response.IsClientConnnected$c$c>第一位。
While I agree with Mitchel - there's little need to call flush as you're about to call End, if you're using this elsewhere, you could try calling Response.IsClientConnnected
first.
获取指示客户端是否仍然连接到服务器的一个值。
这篇关于Response.Flush()抛出System.Web.HttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!