远程主机关闭了连接.错误代码是0x800704CD

web*_*oob 78 asp.net iis-7

每当发生异常时,我都会收到来自我网站的错误电子邮件.我收到此错误:

远程主机关闭了连接.错误代码是0x800704CD

而且不知道为什么.我每天大约30.我无法重现错误,因此无法追踪问题.

网站是在IIS7上运行的ASP.NET 2.

堆栈跟踪:

在System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(的Int32结果,布尔throwOnDisconnect)在System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()在System.Web.HttpResponse.Flush(布尔finalFlush)在System.Web.HttpResponse.Flush( )在System.Web.HttpResponse.End()在System.Web.UI.HttpResponseWrapper.System.Web.UI.IHttpResponse.End()在System.Web.UI.PageRequestManager.OnPageError(对象发件人,EventArgs e)上系统.Web.UI.TemplateControl.OnError(EventArgs e)上System.Web.UI.Page.HandleError(例外五)在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)在System.Web.UI程序. Page.ProcessRequest(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)在System.Web.UI.Page.ProcessRequest()在System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext的上下文)在System.Web.UI.Page.ProcessRequest(HttpContext的上下文)在System.Web.H的ASP.default_aspx.ProcessRequest(HttpContext上下文)ttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔逻辑completedSynchronously)

m.e*_*son 59

我总是得到这个.这意味着用户开始下载文件,然后失败,或者他们取消了.

要重现异常,请尝试自己执行此操作 - 但是我不知道有任何方法可以阻止它(除了仅处理此特定异常).

您需要根据应用确定最佳前进方式.

  • 是的,看看堆栈跟踪`System.Web.HttpResponse.Flush()`意味着任何类型的响应.我刚刚发现[这个](http://blog.whitesites.com/fixing-The-remote-host-closed-the-connection-The-error-code-is-0x80070057__633882307305519259_blog.htm),它可能对你有所帮助到达问题的路径,其中viewstate非常大,用户点击太快会导致此异常. (6认同)
  • 我对此的调查显示,用户看不到任何异常.您有客户/客户的投诉吗? (2认同)
  • 不,没有。谢谢您的帮助。 (2认同)

Sam*_*les 28

正如m.edmondson所说,"远程主机关闭了连接." 当用户或浏览器取消某些内容或网络连接丢失等时发生.但不一定是文件下载,只是对任何导致客户端响应的资源的任何请求.基本上,错误意味着无法发送响应,因为服务器无法再与客户端(浏览器)通信.

您可以采取许多步骤来阻止它发生.如果您手动发送与回复于,Response.Flush响应的东西,从网页servivce /页的方法或类似的东西返回数据,那么你应该考虑发送响应之前,检查Response.IsClientConnected.此外,如果响应可能需要很长时间,或者需要进行大量的服务器端处理,则应定期检查,直到response.end(如果调用).有关此属性的详细信息,请参阅以下内容

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx

或者,我认为最有可能在您的情况下,错误是由框架内的东西引起的.以下链接可能有用:

http://blog.whitesites.com/fixing-The-remote-host-closed-the-connection-The-error-code-is-0x80070057__633882307305519259_blog.htm

以下堆栈溢出帖子也可能是有意义的:

Response.OutputStream.Write中的"远程主机关闭了连接"

  • `Response.IsClientConnected`的大热门! (2认同)

Yar*_*lev 10

可以使用以下代码重现错误:

public ActionResult ClosingTheConnectionAction(){
   try
   {
      //we need to set buffer to false to
      //make sure data is written in chunks
      Response.Buffer = false;  
      var someText = "Some text here to make things happen ;-)";
      var content = GetBytes( someText );

      for(var i=0; i < 100; i++)
      {
         Response.OutputStream.Write(content, 0, content.Length);
      }

      return View();
   }
   catch(HttpException hex)
   {
      if (hex.Message.StartsWith("The remote host closed the connection. The error code is 0x800704CD."))
            {
                //react on remote host closed the connection exception.
                var msg = hex.Message;
            }  
   }
   catch(Exception somethingElseHappened)
   {
      //handle it with some other code
   }

   return View();
} 
Run Code Online (Sandbox Code Playgroud)

现在以调试模式运行网站.在写入输出流的循环中放置一个断点.转到该操作方法,并在第一次迭代通过后关闭浏览器的选项卡.点击F10继续循环.在达到下一次迭代后,您将看到异常.享受你的例外:-)