Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.End() and CompleteRequest()

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.

like image 547
Raed Alsaleh Avatar asked Mar 28 '13 06:03

Raed Alsaleh


People also ask

What can I use instead of response end?

CompleteRequest Instead of Response. End.

What do you use response end for?

The End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.

What is response end in C#?

Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event. public: void End(); C# Copy.


1 Answers

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.

like image 65
Dai Avatar answered Oct 14 '22 05:10

Dai