Response.End() and CompleteRequest()

22,214

HttpResponse.End flushes the output buffer to the client and terminates the current request-handling thread (this is bad), whereas HttpApplication.CompleteRequest tells ASP.NET to immediately skip all future stages in the ASP.NET pipeline and jump directly to the EndRequest step (which also raises the HttpApplication.EndRequest event). The request thread then proceeds with normal end-of-life cleanup.

So, Response.End is like an ejector seat: it quickly ends things, but means you lose control and might be unnecessarily harsh. Whereas CompleteRequest is like making an emergency landing at the nearest airport.

Share:
22,214

Related videos on Youtube

Raed Alsaleh
Author by

Raed Alsaleh

Web Developer in JOVAL company ... working with ERP Systems for

Updated on July 09, 2022

Comments

  • Raed Alsaleh
    Raed Alsaleh almost 2 years

    What are the advantage and disadvantage for each of Response.End() and CompleteRequest()? Where should I and should I not use them? I looked at this question but I didn't get a proper answer.

  • Raed Alsaleh
    Raed Alsaleh over 11 years
    So when I must use Response.End() and When I must use HttpApplication.CompleteRequest()
  • Dai
    Dai over 11 years
    Ideally, you'd never need to use either.
  • marc_s
    marc_s almost 10 years
    Read Correct use of System.Web.HttpResponse.Redirect - Response.End is a risky "ejector seat" ... use with utmost caution...
  • nuander
    nuander almost 8 years
    That's exactly what I need, an ejector seat, but I can't find that method anywhere
  • Dai
    Dai almost 8 years
    @nuander are you using WebAPI, ASP.NET Core or MVC 6? They radically changed the ASP.NET API in those releases.
  • Brain2000
    Brain2000 about 6 years
    Can I assume then it's also a bad idea to call either one when writing your own iHttpHandler?
  • Jay Shah
    Jay Shah over 5 years
    @Dai If the use of HttpApplication.CompleteRequest is not recommended, then how to do proper redirection ? Isn't the Response.Redirect(url, false); followed by Context.ApplicationInstance.CompleteRequest(); proper way ?