每当发生异常时,我都会收到来自我的网站的错误电子邮件。我得到了这个错误:
远程主机已关闭连接。错误代码为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)
发布于 2011-04-06 18:29:43
我经常会遇到这个问题。这意味着用户开始下载一个文件,然后它失败了,或者他们取消了它。
要重现异常,请尝试自己执行此操作--然而,我不知道有什么方法可以防止它(除了只处理这个特定的异常)。
你需要根据你的应用决定最好的前进方式。
发布于 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
或者,我认为在您的情况下最有可能的是,错误是由框架内部的某些东西引起的。以下链接可供使用:
下面的堆栈溢出post可能也很有趣:
"The remote host closed the connection" in Response.OutputStream.Write
发布于 2015-03-26 23:14:00
可以用下面的代码重现这个错误:
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继续循环。在它命中下一次迭代后,您将看到异常。享受您的例外:-)
https://stackoverflow.com/questions/5564862
复制相似问题