views:

631

answers:

2

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.

+3  A: 

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.

Kragen
can you explain both choices in little detail?
Syed Tayyab Ali
obviously, i m using try catch statements to catch this exception.
Syed Tayyab Ali
http://programming360.blogspot.com/2009/10/thread-was-being-aborted.html
Syed Tayyab Ali
+3  A: 

Caling Server.Transfer will call Response.End which always throws a ThreadAbortException. This s a "special" exception because while it can be caught in a catch block, it will always be re thrown at the end of the catch block. I would have your error logging ignore ThreadAbortExceptions.

Matt Wrock
It make sense to me that Server.Transfer will call Response.End implicitly.What do you mean by error logging ignore threadAbortException.
Syed Tayyab Ali
If you are logging exceptions to a persistable logging system, I would filter out ThreadAbortExceptions or have your reports that query this loging system filter them out.
Matt Wrock
It make sense that this exception is not serious one, therefore I can ignore it by filtering out..thank you.
Syed Tayyab Ali