網頁

Thursday, October 6, 2011

[TroubleShooting] The remote host closed the connection. The error code is 0x80072746.

System.Web.HttpException
The remote host closed the connection. The error code is 0x80072746.

System.Web.HttpException (0x80072746): The remote host closed the connection. The error code is 0x80072746.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.HttpResponse.Flush(Boolean finalFlush)
at LunchKingSite.Web.Service.coupon.ProcessRequest(HttpContext context) in c:#############################.cs:line 73
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


公司網站上常常有這個錯誤,不過放了很久卻都沒有人去解,今天找了一下解法,大致上有兩種。

先說說原因,這問題的主要原因通常是在輸出資料時,使用者已經關閉連線(關掉瀏覽器),但是程式卻不知道,於是跑到 Response.Flush(); 的時候,就會產生這個錯誤。

解法一是加上Response.Buffer = false;
解法二是在 Flush 前先用 Response.IsClientConnected 去判斷是否還有連線,有的話再繼續。

這錯誤有點難模擬,所以我沒有兩個都試然後去看結果,所以只用了第一個,解法二看起來還是會有很小的機會發生同樣的錯誤就是。

No comments:

Post a Comment