Response.End () VS Context.ApplicationInstance.CompleteRequest ()
The Server.Transfer, Response.Redirect, Response.End methods all raise exceptions. Each of the these methods internally call Response.End. The call to Response.End, in turn, causes a ThreadAbortException exception.
HTTPS://MSDN.MICROSOFT.COM/EN-US/LIBRARY/FF647787.ASPX#SCALENETCHAPT06_TOPIC22 Performance Sixth Chapter
Server.Transfer, Response.rediret, response.end methods all produce anomalies. Each hair copy will call Response.End, resulting in a threadabortedexception exception
ThreadAbortException Solution
Httpapplication.completerequest () sets a variable that causes the thread to skip past most of the events in the Httpapplic ation event pipeline [--] not the Page event chain but the application event chain.
Response.End and Response.close is not used in normal request processing when performance is important. Response.End is a convenient, heavy-handed means of terminating request processing with an associated performance penalty. Response.close is for immediate termination of the HTTP Response at the iis/socket level and causes issues with things Li Ke KeepAlive.
The recommended method of ending an ASP. Httpapplication.completerequest. Keep in mind that ASP. Rendering'll has to be skipped manually since
Http://web.archive.org/web/20101224113858/http://www.c6software.com/codesolutions/dotnet/threadabortexception.aspx
The variable set by Httpapplication.completerequest () causes the thread to skip most of the HttpApplication pipeline events, not the page event chain, but rather the application event chain
When performance is important, Response.End and response.close are not used for normal request processing. Response.End is a convenient, heavy-duty method to terminate request handling related to performance consumption.
Response.close immediately terminates the HTTP response at the Iis/socket level and causes a keepalive problem like http.
The proposed termination of the ASP. Net request method is httpapplication.completerequest. In the mind is
1. Httpresponse.end flushes the output buffer to the client and terminates the current request-handling thread, whereas H Ttpapplication.completerequest tells ASP. Immediately skip all-stages in the ASP-Pipeline and Jump Direct ly 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 are like a ejector seat:it quickly ends things, but means you lose control and might be unnecessarily ha Rsh. Whereas CompleteRequest is like making a emergency landing at the nearest airport.
1. Response.End internally throws the ThreadAbortException to kill the request-if you need to do some kind of cleanup, t His needs to being do before the call to Response.End is made.
Response.Redirect and Response.End do not interact well with try/catch blocks. So in your situation, you should does all your logic writing to the response stream in your try/catch, then simply call Re Sponse. End after your finally block.
1. Create pdf
Response.OutputStream.Flush ()
Response.OutputStream.Close ()
Response.End ()
Reference: Http://weblogs.asp.net/hajan/why-not-to-use-httpresponse-close-and-httpresponse-end
Response.End () VS Context.ApplicationInstance.CompleteRequest ()