Peter Goodman bio photo

Peter Goodman

A software engineer and leader living in Auckland building products and teams. Originally from Derry, Ireland.

Twitter Google+ LinkedIn Github

A colleague came across a problem recently where performance counters were showing a high exception to request ratio. In actual fact there were at 4 exceptions for every 1 request, that's 400% compared to the desired 5%. These seemed to be getting handled at some stage or another as there were no HttpUnhandledExceptions getting thrown at the UI.

It turns out that Response.Redirect and Server.Transfer will throw a ThreadAbortException everytime the single parameter overload is called.

i.e. Response.Redirect( string url )

The problem is that Response.Redirect will call a Response.End internally to stop code executing after the statement. This in turn throws our mystery exceptions. To work around this use the overloaded version which allows code after the statement to be executed and try not to treat the statement as the end of a code block.

i.e. pass "false" to second param of

Response.Redirect( string url, bool endResponse )

There is a lot of fair argument to say that this shouldn't cause an exception. So if you see unexplained high exception counters, have a look at your Response.Redirects and Server.Transfers.

MSDN Article: PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

P.S. Thanks to Josh Twist at MS for pointing this one out. ;)