The remote host closed the connection. The error code is 0x800704CD

前端 未结 6 1163
说谎
说谎 2020-12-03 00:33

I receive error emails from my website whenever an exception occurs. I am getting this error:

The remote host closed the connection. The error code is

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 01:00

    I too got this same error on my image handler that I wrote. I got it like 30 times a day on site with heavy traffic, managed to reproduce it also. You get this when a user cancels the request (closes the page or his internet connection is interrupted for example), in my case in the following row:

    myContext.Response.OutputStream.Write(buffer, 0, bytesRead);
    

    I can’t think of any way to prevent it but maybe you can properly handle this. Ex:

            try
            {
                …
                myContext.Response.OutputStream.Write(buffer, 0, bytesRead);
                …
            }catch (HttpException ex)
            {
                if (ex.Message.StartsWith("The remote host closed the connection."))
                    ;//do nothing
                else
                    //handle other errors
            }            
            catch (Exception e)
            {
                //handle other errors
            }
            finally
            {//close streams etc..
            }
    

提交回复
热议问题