The Response.Redirect method is often used in webpages to redirect users to other pages as part of the web application. ASP.NET offers different ways to build redirection into webpages :
- Using hyperlinks on pages.
- Configuring cross-page posting, which enables you to specify an alternate target page when the current page is submitted.
- Redirecting programmatically by forcing the browser to request a different page.
- Redirecting programmatically by transferring control to a different page in the same Web application.
Recently I saw a lot of exceptions (System.Threading.ThreadAbortException
) in the logfile of a web application. It was quickly clear that this was caused by all redirections set in the web application. The third method (see above) was used to programmatically redirect users to other webpages in the web application, but the Response.Redirect method was always used without the optional/overloaded endResponse
boolean parameter. This parameter indicates whether execution of the current page should terminate. If not set to false (default = true), the Redirect method will always generate a System.Threading.ThreadAbortException
and will immediately stop executing any additional code.