异常(消息):远程主机关闭了连接。错误代码是0x800703E3

问题描述 投票:0回答:1

我在我的应用程序中收到此错误。我在错误日志中经常看到这些错误,但我不确定来源。这是错误的堆栈跟踪。

Exception (Stack):    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)    
at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()     
at System.Web.HttpResponse.Flush(Boolean finalFlush)     
at System.Web.Mvc.FileContentResult.WriteFile(HttpResponseBase response)     
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()     
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)     
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)     
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

但在做了一些谷歌搜索后,我发现原因可能是我下载文件的方式,但我不确定。这也是源代码。

string Id = id.Split(new[] { '!' }).First();
DocumentInfo Content = Doc.ContentDownLoad(Settings, docId);
Response.Clear();
Response.BufferOutput = false;  
fileName = Content.DocName + "." + Content.FileExtn;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);

return File(Content.Content, Content.MimeType);

我尝试了一些建议的解决方案,但没有任何工作。有人可以提出可行的解决方案吗我在这做错了什么?

c# asp.net-mvc-4
1个回答
0
投票

此异常表示用户通过关闭浏览器或导航到另一个页面,在文件下载完成之前关闭了连接。用户永远不会看到此错误,但Elmah会记录它。您可以在写入下游之前检查您的客户端是否已连接,但它无法完全解决问题。

if (Response.IsClientConnected)
{
   // write your file to down stream 
}

我建议你使用Elmah的过滤器来阻止Elmah记录它。 elmah Error Filtering

© www.soinside.com 2019 - 2024. All rights reserved.