Microsoft Knowledge Base Email Alertz

(312629) - If you use the Response.End , Response.Redirect , or Server.Transfer method, a ThreadAbortException exception occurs. You can use a try-catch statement to catch this exception.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 312629 - Last Review: August 1, 2003 - Revision: 2.6

PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

This article was previously published under Q312629

SYMPTOMS

If you use the Response.End, Response.Redirect, or Server.Transfer method, a ThreadAbortException exception occurs. You can use a try-catch statement to catch this exception.

CAUSE

The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.

This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

RESOLUTION

To work around this problem, use one of the following methods:
  • For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.
  • For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example:
      Response.Redirect ("nextpage.aspx", false);
    						
    If you use this workaround, the code that follows Response.Redirect is executed.
  • For Server.Transfer, use the Server.Execute method instead.

STATUS

This behavior is by design.

APPLIES TO
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
Keywords: 
kbexcepthandling kbprb KB312629
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

D. Chin-Yet Report As Irrelevant  
Written: 1/14/2005 3:06 PM
I had this ThreadAbort error on my response.End() statement occur in a program that was previously working ok. The code was writing data to an excel spreadsheet. partial code: dgAddr.DataBind dgAddr.RenderControl(htmlWrite) 'output the html response.Write(stringWrite.ToString) response.End() 'close the connection MyConnection.Close() After searching the net for answers, I finally reached your article and realized that the response.end() had to be moved. I moved it after Myconnection.Close and the ThreadAbort error went away. I am not using server.transfer or response.redirect in this module. I find this to be very bizarre since it was working for a couple of months before this happened. Anyway, thanks for pointing me in the right direction.

Argumentrain - http://www.database-empire.com Report As Irrelevant  
Written: 1/4/2010 3:49 AM
Liability Pick,stop set exist change cost wear transport effective editor boy obviously forest buy criterion business before face long this odd convention seat popular connect no middle blue matter thought individual relate partner highly prime separate growing so aye contribute hardly myself understand spend throw consider response surround video light necessary temperature difference better clearly notion around leadership slightly index air alternative matter car committee bear this proper pool into audience forget concentration bright child provide complex very park competition question match define reflect wood publication