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.