首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >远程主机已关闭连接。错误代码为0x800704CD

远程主机已关闭连接。错误代码为0x800704CD
EN

Stack Overflow用户
提问于 2011-04-06 18:26:25
回答 6查看 137.5K关注 0票数 84

每当发生异常时,我都会收到来自我的网站的错误电子邮件。我得到了这个错误:

远程主机已关闭连接。错误代码为0x800704CD

也不知道为什么。我一天能拿到30个。我也不能重现这个错误,所以不能追踪这个问题。

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

堆栈跟踪:

System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32结果处的

,System.Web.UI.PageRequestManager.OnPageError(Object发送者处的System.Web.UI.HttpResponseWrapper.System.Web.UI.IHttpResponse.End()处的System.Web.HttpResponse.Flush()处的System.Web.HttpResponse.Flush处的Boolean throwOnDisconnect) (Boolean finalFlush),布尔e)在System.Web.UI.TemplateControl.OnError(EventArgs e)在System.Web.UI.Page.HandleError(例外e)在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)在System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,在System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext上下文的System.Web.UI.Page.ProcessRequest()处的布尔includeStagesAfterAsyncPoint)在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤的System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()处的System.Web.UI.Page.ProcessRequest(HttpContext上下文)处的ASP.default_aspx.ProcessRequest(HttpContext上下文),Boolean& completedSynchronously)

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2011-04-06 18:29:43

我经常会遇到这个问题。这意味着用户开始下载一个文件,然后它失败了,或者他们取消了它。

要重现异常,请尝试自己执行此操作--然而,我不知道有什么方法可以防止它(除了只处理这个特定的异常)。

你需要根据你的应用决定最好的前进方式。

票数 61
EN

Stack Overflow用户

发布于 2012-03-08 17:22:21

作为m.edmondson mentioned,“远程主机关闭了连接。”当用户或浏览器取消某些操作,或网络连接中断等时发生。但是,它不一定是文件下载,只是对任何资源的任何请求都会导致对客户端的响应。基本上,该错误意味着无法发送响应,因为服务器无法再与客户端(浏览器)通信。

为了阻止这种情况的发生,你可以采取一些步骤。如果您手动发送响应中包含Response.Write、Response.Flush、从web服务/页面方法或类似方法返回数据的内容,则应考虑在发送响应之前检查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

下面的堆栈溢出post可能也很有趣:

"The remote host closed the connection" in Response.OutputStream.Write

票数 34
EN

Stack Overflow用户

发布于 2015-03-26 23:14:00

可以用下面的代码重现这个错误:

代码语言:javascript
复制
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();
} 

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

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5564862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档