How to avoid System.Threading.ThreadAbortException in Response.Redirect?

Posted by Sheonarayan under ASP.NET category on | Points: 40 | Views : 1513
In general, when you use Response.Redirect("url") inside the try block, it throws ThreadAbortException at run time.

The solution that is suggested is to use the overload of Response.Redirect("url", false) that tells the machine that do not end response at this line so when the redirection is in place, the next statement keep executing that is not a good practice.

The ideal solution of this problem is to use CompleteRequest method like below.

Response.Redirect("~/codes/", false);

In this case, ASP.NET by passes all events and filtering in ASP.NET pipeline chain and directly executes HttpApplication.EndRequest event that doesn't cause ThreadAbortException error.

Thanks for reading.

Comments or Responses

Login to post response