Response.Redirect has two overloads:
public void Redirect(string url) Parameters: url: The target location.
public void Redirect(string url, bool endResponse) Parameters: url: The location of the target. endResponse: Indicates whether execution of the current page should terminate.
If I call the first overload, or call the second with endResponse set to true a ThreadAbortException gets thrown.
Why would I ever want to use this approach? Isn’t this an example of using exceptions to handle program flow? (and therefore a bad thing)
And if my redirection did warrant an exeption, wouldn’t it be preferable for me to throw a more informative exception that includes the reason for the redirect?
If you set endResponse to ‘true’, you are effectively saying ‘I am done with this page, ignore anything after me’.
The reason a ‘ThreadAbortException’ is raised is so that any Finallys/Catches etc that you have written are fired, and resources are correctly cleaned up before you are sent to the next page.
From MSDN: