HttpContext throws HttpException

the remote host closed the connection the error code is 0x800703e3
the remote host closed the connection the error code is 0x800704cd

I have written a custom http handler. I have done this by writing a class which implements the IHttphandler.

Inside that class I have code like this,

context.Response.AddHeader("Content-Disposition", "attachment;filename=" + attachmentFileName);
context.Response.AddHeader("Content-Length", new FileInfo(downloadFile).Length.ToString());
context.Response.ContentType = GetMimeType(attachmentFileName);

Occasionally I receive an error like this,

Exception HttpException The remote host closed the connection The error code is 0x800703E3

Or this,

Exception HttpException The remote host closed the connection The error code is 0x80070040

In both cases the stack trace is this,

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.HttpResponse.Flush()

This occurs in production, and if I look back over the last few days errors have occurred 23 times, and in total the above code has been called 497 times.

I suspect this failure relates to the user clicking the link to initiate the above code more than once (which will give them multiple download dialogs) then they cancel some of them. Having said that if it was something like that I would have expected the connection to close gracefully at both ends.

How can I prove the exact cause of this error? I have tried to enable .NET tracing like this Why don't trace listeners log custom handler traffic? but couldn't get it to work.

What I found though is that I have enabled IIS tracing to log failed requests. The failure occurred again, and NOTHING was in that log.

Any other tracing I can enable for instance?

The next thing I tried was this,

if (context.Response.IsClientConnected)
    LogMessage("Client has disconnected before flush was called", Severity.Information);

But that didn't make any difference. The reason though I guess is that the client disconnected while the download was taking place, not before flush was called.

Take out both the Flush() and Close() call. You really don't need them. Once your handler is done, it'll exit, and ASP.NET will handle closing the request.

Besides, Flush() should be used when you're streaming content to the client (adding parts to the response stream in blocks). You don't need to use it with TransmitFile().

Java Code Examples org.apache.http.HttpException, @Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { RequestLine line  @peter, it's a good idea if you need to end a request in the middle of processing for some reason. If you have a dedicated handler that does one thing and reaches the end of it's natrual processing, you don't need to do anything, just return from your handler.

I was into similar issues, got this article which explains that Response.End() should be avoid ed and instead suggests to use CompleteRequest() method. MSDN documentation has also been updated with this information. I hope this helps someone.

Java Code Examples of org.apache.http.HttpException, 200) throw new HttpException("Invalid response code: " + response. public void process(HttpRequest request,HttpContext ctx) throws HttpException,  HttpContext throws HttpException. Ask Question Asked 8 years, it throws a thread abort exception and everything else turns to custard. – peter Apr 5 '11 at 23:11.

Use Response.End() instead of Response.Flush()

This is what the source code for Response.End() looks like:

public void End()
    if (this._context.IsInCancellablePeriod)
        Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));
    else if (!this._flushing)
        this._ended = true;
        if (this._context.ApplicationInstance != null)

Handle errors in ASP.NET Core web APIs, OrdinalIgnoreCase)) { throw new ArgumentException( $"We don't offer a weather forecast for {city}. Invoke(HttpContext context) at Microsoft. The Button_Click method determines which button was clicked, and then calls either the CheckNumber or CheckBoolean method. If the user-entered value in the text box does not correspond to the expected type, an HttpException exception is created and thrown with a customized message based on the error type.

What .NET framework are you using? This forum thread here describes a similar problem using IIS7 with .NET2.0 specifically to do with the client disconnect, a problem which was addressed in .NET framework 3.5

The actual error code maps to

0x800703E3 "The I/O operation has been aborted because of either a thread exit or an application request."

System.Web.HttpException: Request is not available in this context , [HttpException (0x80004005): Request is not available in this context]. System.​Web.HttpContext.get_Request() +3465893. AspNet.StarterKits. Java Code Examples for org.apache.http.HttpException. The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

try to set up the max size file on the web config to a bigger one.

You can set the maxRequestLength (in kb)

try to not reclycle app pools on iis to often also.

HttpRequestExecutor (Apache HttpComponents Core HTTP/1.1 5.0 , of an I/O error. HttpException - in case of HTTP protocol violation or a processing problem. conn, HttpContext context) throws IOException, HttpException. The following are top voted examples for showing how to use org.apache.http.HttpException.These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.

BasicClientExchangeHandler (Apache HttpComponents Core HTTP , httpContext - the actual execution context. Throws: streamEnd. public void streamEnd(List<? extends Header> trailers) throws HttpException, IOException. Remarks. The Request property provides programmatic access to the properties and methods of the HttpRequest class. Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpRequest on an .aspx page without using the fully qualified class reference to HttpContext.

BlackBerry Dynamics: DefaultRequestDirector Class Reference, Determines the route for a request. More void, establishRoute (HttpRoute route, HttpContext context) throws HttpException, IOException. Establishes the target  [HttpException (0x80004005): Request is not available in this context] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +3465475 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +69

org.apache.http.protocol.HttpContext java code examples, @Override public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { // Avoid work if TRACE is not enabled for this​  This article covers common approaches to handling errors in ASP.NET Core web apps. See Handle errors in ASP.NET Core web APIs for web APIs. View or download sample code. ( How to download .) The article includes instructions about how to set preprocessor directives ( #if, #endif, #define) in the sample app to enable different scenarios.