Thread Abort Exception !!!


 

Recently I worked with one of our customer who was facing Thread abort exception and he was unable to login to his site. The exception showed up in Application logging which customer had set up.

we see there is a redirection issue when we enter values in text boxes and click on submit button on a URL

https://Custom-Site.Foo.com/Example/Summary.aspx

it redirects us to home.aspx which is not expected. we must see the data entered is submitted to DB and get a message on screen. this was customers requirement.

We see Error :

Thread was being aborted.

   at Com.D.Dt.Facts.D.EventD.SaveEvent()

   at EIGDefault.SaveEventAndReport(Boolean finishLatter)

EIGDefault.aspx.SaveEventAndReport

12/4/2014 12:00:00 AM 014373700

Thread was being aborted.

   at Com.De.Dt.Facts.D.EventD.GetParameters(String DBOperation)

   at Com.De.Dt.Facts.D.EventD.SaveEvent()

EventD.SaveEvent

12/4/2014 12:00:00 AM 014373700

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)

   at Com.D.Dt.Facts.D.EventD.GetParameters(String DBOperation)

EventD.GetParameters

 

Resolution or Work Around :

==============================

We found Thread Abort exception comes by default if we use Server.transfer.

There was a confusion on why the redirection was happening. later we found that BIG F5 which was load balancer had a update which caused this “Redirection and updating Load balancer Firmeware it fixed issue of redirection.

But, the reason for Thread Abort exception was not load balancer instead the use of  Server.transfer in code.

Which According to this article will cause Thread Abort Exception.

https://support.microsoft.com/en-us/kb/312629

From the article : If you use the Response.End, Response.Redirect, or Server.Transfer method, a ThreadAbortException exception occurs.

Work around this problem, use one of the following methods:
For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.
For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example:

  Response.Redirect ("nextpage.aspx", false);
If you use this workaround, the code that follows Response.Redirect is executed.

---> For Server.Transfer, use the Server.Execute method instead.

 

Cheers,

Irfan

Skip to main content