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
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.
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.
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.
This behavior is by design.
APPLIES TO
- Microsoft ASP.NET 1.1
- Microsoft ASP.NET 1.0
| 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