Sunday, March 14, 2010

ThreadAbortException in IIS 7 TransferRequest

IIS Integrated Mode

In some web applications we have to transfer the web request, but with IIS 7.0 HttpServerUtility.TransferRequest trows ThreadAbortException whis is really annoying. We have to manually handle the exception.

The reason for this is

On the Integration mode for Internet Information Services (IIS) 7.0, the HttpServerUtility.TransferRequest method incorrectly uses the HTTPResponse.End method to stop the parent request. This results in throwing a ThreadAbortException, which can impact performance for terminating execution of a response. In the .NET Framework 3.5 SP1, the TransferRequest method now ends the parent request by using the HttpApplication.CompleteRequest method. This also terminates the current request gracefully by transferring control to the HttpApplication.EndRequestevent handler without throwing an exception.

Suggested modifications with when you install .NET framework SP1: If you have error-handling code that uses the TransferRequest method to determine whether the ThreadAbortException was thrown, you can remove that code from the catch block.

2 comments:

Unknown said...

We have had lot of issues with this ThreadAbort exception and as you said it had resulted in lot of empty catch blocks just to get around. If we use Server.Transfer instead of Response.Redirect will there be a change?

Thanks for the post. This will result in much cleaner web code in 3.5.

Lakmal said...

This is a disaster, even though we handled this, in my case all the session variables were getting lost...

Thank you for the post....