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

前端 未结 6 1176
说谎
说谎 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 00:50

    One can reproduce the error with the code below:

    public ActionResult ClosingTheConnectionAction(){
       try
       {
          //we need to set buffer to false to
          //make sure data is written in chunks
          Response.Buffer = false;  
          var someText = "Some text here to make things happen ;-)";
          var content = GetBytes( someText );
    
          for(var i=0; i < 100; i++)
          {
             Response.OutputStream.Write(content, 0, content.Length);
          }
    
          return View();
       }
       catch(HttpException hex)
       {
          if (hex.Message.StartsWith("The remote host closed the connection. The error code is 0x800704CD."))
                {
                    //react on remote host closed the connection exception.
                    var msg = hex.Message;
                }  
       }
       catch(Exception somethingElseHappened)
       {
          //handle it with some other code
       }
    
       return View();
    } 
    

    Now run the website in debug mode. Put a breakpoint in the loop that writes to the output stream. Go to that action method and after the first iteration passed close the tab of the browser. Hit F10 to continue the loop. After it hit the next iteration you will see the exception. Enjoy your exception :-)

提交回复
热议问题