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 toResponse.End()
internally, and it'sResponse.End()
that callsThread.Abort()
which bubbles up the stack to end the thread. Under rare circumstances the call toResponse.End()
actually doesn't callThread.Abort()
, but instead callsHttpApplication.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.