HttpContext throws HttpException

前端 未结 7 615
无人共我
无人共我 2020-12-05 18:30

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,



        
相关标签:
7条回答
  • 2020-12-05 19:04

    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."
    
    0 讨论(0)
  • 2020-12-05 19:05

    For more details about this exception visit http://support.microsoft.com/kb/977453

    0 讨论(0)
  • 2020-12-05 19:18

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

    0 讨论(0)
  • 2020-12-05 19:23

    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.

    http://blogs.msdn.com/b/aspnetue/archive/2010/05/25/response-end-response-close-and-how-customer-feedback-helps-us-improve-msdn-documentation.aspx

    0 讨论(0)
  • 2020-12-05 19:24

    I have the error sometimes:

    Exception message: An error occurred while communicating with the remote host. The error code is 0x80070057.
    

    Is random in production. Its not reproduce in Development or QA.

    I will apply this solution: Response.IsClientConnected I hope it will fix the error.

    Source:

    https://stackoverflow.com/a/11441375/1536197

    0 讨论(0)
  • 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)
        {
            InternalSecurityPermissions.ControlThread.Assert();
            Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));
        }
        else if (!this._flushing)
        {
            this.Flush();
            this._ended = true;
            if (this._context.ApplicationInstance != null)
            {
                this._context.ApplicationInstance.CompleteRequest();
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题