Exception (Message): The remote host closed the connection. The error code is 0x800703E3

1

I'm getting this error in my application. I see these errors quite often in my error logs but I'm not sure of the source. Here is the stack trace for the error.

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)

But after doing some googling I found that the reason could be the way I'm downloading the file, but I'm not sure. Here is the source code too.

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);

I tried some suggested solutions here but nothing is working. Could someone suggest a feasible solution? What am I doing wrong here?

c#
asp.net-mvc-4
asked on Stack Overflow Feb 28, 2014 by Sri • edited Dec 18, 2017 by rgettman

1 Answer

0

This exception indicates that the user closed the connection before the file had finished downloading by closing his/her browser or navigating to another page. Users never see this error but Elmah logs it. You can check your client is connected before writing to down stream but it can not solve the problem completely.

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

I suggest you use Elmah's filters to prevent Elmah from logging it. elmah Error Filtering

answered on Stack Overflow Jul 20, 2014 by Karim

User contributions licensed under CC BY-SA 3.0