Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.Redirect and thread was being aborted error?

I had this error Thread was being aborted., this afternoon in my error log.

The code that caused this error is:

Response.Redirect("Login.aspx", true);

If I change the bool value to false, the error log becomes empty and this error stops coming again, but the program stops working.

If I keep it as such, I am getting this error like nuisance.

I want to know the alternative for using Response.Redirect passing true as the value for the endResponse parameter.

like image 466
Karthik Ratnam Avatar asked Dec 06 '10 16:12

Karthik Ratnam


1 Answers

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.
}
like image 110
Colin Mackay Avatar answered Oct 20 '22 09:10

Colin Mackay