Tuesday, January 22, 2008 9:35 PM
If you have ever seen this exception while debugging a web application:
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code
To cut down on exceptions in your ASP.NET applications with Response.Redirect, you need to use the overloaded redirect method. Under the hood, the CLR will throw an exception to ensure the page execution is halted.
private void SomeEvent(object sender, System.EventArgs e)
{
//This will throw an exception so that the CLR ensures the end of execution.
Response.Redirect("http://www.threadabort.com");
//This performs better when this overload function's second arg is set to false
//because an exception will not be thrown.
Response.Redirect("http://www.threadabort.com", false);
}
The only issue is that the page continues to execute. This may not be desired.