Response.End() and CompleteRequest()
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.
Related videos on Youtube
![Raed Alsaleh](https://i.stack.imgur.com/GR4Vl.jpg?s=256&g=1)
Raed Alsaleh
Web Developer in JOVAL company ... working with ERP Systems for
Updated on July 09, 2022Comments
-
Raed Alsaleh almost 2 years
What are the advantage and disadvantage for each of
Response.End()
andCompleteRequest()
? Where should I and should I not use them? I looked at this question but I didn't get a proper answer. -
Raed Alsaleh over 11 yearsSo when I must use Response.End() and When I must use HttpApplication.CompleteRequest()
-
Dai over 11 yearsIdeally, you'd never need to use either.
-
marc_s almost 10 yearsRead Correct use of System.Web.HttpResponse.Redirect -
Response.End
is a risky "ejector seat" ... use with utmost caution... -
nuander almost 8 yearsThat's exactly what I need, an ejector seat, but I can't find that method anywhere
-
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 about 6 yearsCan I assume then it's also a bad idea to call either one when writing your own iHttpHandler?
-
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 ?