Solution for "Thread was being aborted" exception when you call Response.End (or .Redirect)

You’ve probably seen this one.

Whenever you do one of the following:

Response.End()
Response.Redirect("page.aspx")
Server.Transfer("page.aspx")

You end up with a ThreadAbortException, “Thread was being aborted”.

I had previously dealt with this by swallowing the ThreadAbortException, which of course isn’t a great method, but it worked.

Well today I came across a better way for all of these.

Replace This With This
Response.End HttpContext.Current.ApplicationInstance.CompleteRequest
Response.Redirect(“page.aspx”) Response.Redirect(“page.aspx”,false)
Server.Transfer(“page.aspx”) Server.Execute(“page.aspx”)
Advertisement

One thought on “Solution for "Thread was being aborted" exception when you call Response.End (or .Redirect)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s