ThreadAbortException and Response.Redirect


Some time ago, I developed an application framework for a company which relied on dynamically loaded user controls. The user controls and their location as well as what page they were supposed to appear on were entirely data driven by a configuration table in the database. The issue was though, that since it was on a Web Farm, we wanted to avoid state persistence as much as possible. As a result, we used request variables via the URL and used Response.Redirect and Server.Transfer. However, one problem arose out of this, surrounding the use of the Response.Redirect method and ostensibly the Server.Transfer method (Server.Transfer calls Response.Redirect internally). Each time I redirected, an exception would be thrown. I actually didn't realize this was happening until I stepped through the code trying to debug an unrelated issue and found that I was somehow in my catch block. The issue is that the Response.End method, which is natively called after Response.Redirect abruptly ends page execution by sending the execution to the Application_EndRequest event. This causes anything after Response.End never to be executed. As a result, an exception is thrown. To resolve this, specify the end Response for the Response.Redirect to be false. This suppresses the Response.End call and no exception is thrown. See the KB article.

Skip to main content