Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Tuesday, December 26

Response.Redirect - ThreadAbortException

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.

4 Comments:

  • At 3:53 PM, Anonymous Anonymous said…

    Server.Transfer also generates this exception. Using Reflector I've found that it calls Server.Execute, then Response.End

     
  • At 1:38 AM, Anonymous Anonymous said…

    You get the same result (without the threadabort exception with the following)

    Response.Redirect("myurl", false);
    HttpContext.Current.ApplicationInstance.CompleteRequest();

     
  • At 1:53 AM, Anonymous Anonymous said…

    Crap, i was thinking about Response.End (which throws a TAE too)

    And after a bit of searching i ended up at: http://support.microsoft.com/default.aspx?scid=kb;EN-US;312629

     
  • At 9:18 AM, Blogger patrick said…

    Nice blog! Thank you for this sharing..... web application

     

Post a Comment

<< Home