Response.Redirect and thread was being aborted error? Response.Redirect and thread was being aborted error? asp.net asp.net

Response.Redirect and thread was being aborted error?


I catch this exception and swallow it because ASP.NET is using exceptions for flow control rather than for an exceptional circumstance.

try{    // Do stuff.}catch(ThreadAbortException){    // Do nothing. ASP.NET is redirecting.    // Always comment this so other developers know why the exception     // is being swallowed.}catch(OtherExceptionTypes ex){    // Log other types of exception.}


As stated in Response.Redirect(url) ThreadAbortException Solution:

The ThreadAbortException is thrown when you make a call to Response.Redirect(url) because the system aborts processing of the current web page thread after it sends the redirect to the response stream. Response.Redirect(url) actually makes a call to Response.End() internally, and it's Response.End() that calls Thread.Abort() which bubbles up the stack to end the thread. Under rare circumstances the call to Response.End() actually doesn't call Thread.Abort(), but instead calls HttpApplication.CompleteRequest().

Or simply move Response.Redirect("~/Membership/UserRegistration.aspx"); out of the Try/Catch block.


you can change like this Response.Redirect ("Login.aspx",false)then it wont abort.