Thread was being aborted

Syed Tayyab Ali picture Syed Tayyab Ali · Sep 16, 2009 · Viewed 92.6k times · Source

I am using Server.Transfer. Everything works fine, but exception log shows following exception.

System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Threading.Thread.AbortInternal()
   at System.Threading.Thread.Abort(Object stateInfo)
   at System.Web.HttpResponse.End()
   at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
   at System.Web.HttpServerUtility.Transfer(String path)

Any idea to avoid above exception.

Answer

Justin picture Justin · Sep 16, 2009

This exception is throw by the call to Server.Transfer in order to halt the execution of the current method - exactly the same thing gets thrown if you do Response.Redirect.

The two choices you have are:

  • Catch and rethrow the ThreadAbortException / reperform the Server.Transfer
  • Make sure that you only do Server.Transfer in places where it wont be caught (recommended)

EDIT: Scratch that, http://support.microsoft.com/kb/312629 has a couple of other suggestions to try, but I still recommend #2 above.