Thread was being aborted when we use
This is the way the Redirect works when you do not let the rest of the page continue to run. Its stop the thread and throw that abort exception. You can simple ignore it as:
try
{
Response.Redirect("newpage.aspx", true);
}
catch (System.Threading.ThreadAbortException)
{
// ignore it
}
catch (Exception x)
{
}
Attention
If you call the redirect with out stopping the rest of the processing, a hack that can stop the redirect process using a plugin like the NoRedirect can see your rest of the page .!
To prove my point here I make a question about : Redirect to a page with endResponse to true VS CompleteRequest and security thread
Response.Redirect
without specifying the endResponse
parameter as false
(default is true
) will call Response.End()
internally and therefore will trigger a ThreadAbortException
to stop execution.
One of two things are recommended here:
If you need to end the response, do not do it in a try/catch. This will cause the redirect to fail.
If you do not need to end the response, call this instead:
Response.Redirect(url, false);
Within try/catch:
try {
// do something that can throw an exception
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
} catch (SomeSpecificException ex) {
// Do something with the caught exception
}
To avoid postback handling and HTML rendering, you need to do more:
http://web.archive.org/web/20101224113858/http://www.c6software.com/codesolutions/dotnet/threadabortexception.aspx
http://support.microsoft.com/kb/312629
as you can see here the problem is that you are attempting to use response.redirect in a try/catch block. It thrown an exception.
Your solution of changing the call to be Response.Redirect(url, false)
should work. You need to make sure to do it on every Response.Redirect call.
Also note that this will continue execution, so you will have to handle that (prevent it from continuing in some other way).