2009-10-12 2 views
10

가 발생합니다. 이미지 스트림을 응답 객체에 출력하고 플러시를 호출 할 때가끔 오류가 발생합니다. 여기에 내가 읽은 것과는 코드 블록Response.Flush를()는 내가 클라이언트의 웹 사이트에 특정 이미지를 처리하기 위해 사용 해요 HttpHandler를이 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)

에서 떨어진다/블록 잡기.? 다음 줄부터 구현에 개인적으로

답변

6

나는 Mitchel에 동의하지만, End를 호출 할 때 flush를 호출 할 필요가 거의 없으며 다른 곳에서이 호출을 사용하는 경우 Response.IsClientConnnected을 먼저 호출 해 볼 수 있습니다.

클라이언트가 서버에 계속 연결되어 있는지 여부를 나타내는 값을 가져옵니다.

+0

그래서, 나는 .IsClientConnected 내 .Flush()와 .END()를 포장하고 내 문제를 생각하십니까 해결 할 수? 고객의 고객은 화면에 오류를 표시하지 않고 ELMAH로부터 매번 이메일을받습니다. 그냥 사소한 성가심이 무엇보다. –

+0

당신은 확실히 체크에 .Flush을 포장 할 수 - .END를 호출하지의 영향에 대해 너무 확실하지 ... 내가 거기 그 이미지를 생성 완료했습니다 전에 사람들이 분리의 원인에 일부 긴 실행중인 프로세스가있을 것 같은데요? –

+0

.IsClientConnected 내부를 래핑하는 것이 동일한 예외를 throw 할 수 있음을 확인할 수 있습니다. 지금 당장 나에게 일어났다. .End()로 고집하기 – Contra

11

는()으로 Response.End()가 바로으로 Response.End로 Response.Flush를 호출()를 제거하는 당신을 위해 모든 것을 처리합니다.

0

나는 이것이 오래된 게시물이라는 것을 알고 있지만 비슷한 문제에 대한 답변을 찾을 때 나타났습니다. 다음은 대체로 this SO answer에서 축약됩니다. 자세한 배경 정보는 Is Response.End() considered harmful?에서 확인할 수 있습니다. 이와 HttpContext.Current.Response.End();

:

이 교체

HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client. 
HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event. 
관련 문제