Response.End() and CompleteRequest()

Raed Alsaleh picture Raed Alsaleh · Mar 28, 2013 · Viewed 19.9k times · Source

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.

Answer

Dai picture Dai · Mar 28, 2013

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.