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”) |
I also get this error with Server.Execute("page.aspx") method.