Click here to Skip to main content
13,146,934 members (80,637 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 19 Nov 2010

Why not to pass endResponse parameter as true in Response.Redirect method

, 15 Dec 2010
Rate this:
Please Sign up or sign in to vote.

As per MSDN documentation, Redirect method calls Response.End() method which internally tries to raise ThreadAbortException. If the attempt is successful the calling thread gets aborted which has adverse affect on your site performance.

It is advised and recommended to call the method as Response.Redirect(url, false). And then call CompleteRequest method which causes ASP.NET by pass all its events in the HttpPipeline directly jumping to EndRequest method. See HttpPipeline event model

Please note: CompleteRequest allows your page life cycle event to execute. Consider following scenario.

Code Snippet

Line1: try {
Line2: Response.Redirect(url, true);
Line3: }
Line4: catch(ThreadAbortException ex) {
Line5: // Do nothing
Line6: }

In the above snippet if we pass true in Redirect method, it will surely throw a ThreadAbortException. So if we follow the Microsoft recommended solution, we don't need to add try..catch block. Because CompleteRequest method does not throws any exception neither interrupts the ASP.NET Page life cycle events, rather it jumps HttpPipeline events (refer to this[^] link for Http Pipeline event model).

Recommended: Code Snippet

Line1: Response.Redirect(url, false);
Line2: this.Context.ApplicationInstance.CompleteRequest();


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

M.Nadeem Shaikh
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Member 954405021-Aug-13 20:23
memberMember 954405021-Aug-13 20:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 15 Dec 2010
Article Copyright 2010 by M.Nadeem Shaikh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid