Response.Redirect throws _Thread was being aborted_
While working on a project, I got this error on doing a Response.Redirect operation. When I searched for reasons behind this error, I got the following results:
1) Server.Transfer and Response.Redirect methods redirect users to another page and internally call Response.End method. Response.End immediately ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline.
2) By design, .Net automatically throws a ThreadAbortException on a Response.Redirect operation. To avoid this, set the 2nd parameter (EndResponse ) of redirect operation to false. Since we are bypassing end response, ThreadAbortException method will not be called.
3) Move Response.Redirect method outside the try/catch block. If there is a need to handle exceptions then first catch ThreadAbortException exception and do nothing in that catch block. Put your other exceptions blocks below ThreadAbortException block.
// Do stuff.
// Do nothing. ASP.NET is redirecting.
// Log other exceptions.
4) Write your own custom redirect function like the one shown below
Private void Redirect(string url, bool hasErrored)
5) None of the above solutions worked for me. In my case, error was due to wrong page path. I was redirecting to the page above the root directory .i.e. I added extra.. In the path of redirect method. Using ~ sign for root directory worked. Make sure you are redirecting the page to the valid location.
Images used on this website
are either a production of Bhaktivedanta Book Trust(http://www.krishna.com), Iskcon
Foundation or were found in google search under "Free to use and share". If any
of the images presented here violates copyright issues or infringes anyone copyright
or are not under "Fair use", then please bring it to our notice. Read Disclaimer
Share this to your friends. One of your friend is
waiting for your share.
Uploading file asynchronously using Ajax AsyncFileUpload control
How AJAX Works, advantages and disadvantages
Jquery features, Advantages and disadvantages
Working with server controls and HMTL controls
Working with canvas in silverlight
Silverlight New features & system requirement
Working with forms-Jquery form selector
Increase performance of your website using caching
Working with wrap panel in silverlight
Show Update Progress Animation-Ajax