Click here to check my latest exciting videos on youtube
Search Mallstuffs

Flag Counter
Spirituality, Knowledge and Entertainment


Locations of visitors to this page


Latest Articles


Move to top
Response.Redirect throws _Thread was being aborted_
Posted By Sarin on Nov 18, 2012     RSS Feeds     Latest Hinduism news
15181 Views

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.
        Try
  {
    // Do stuff.
}
catch(ThreadAbortException)
  {
    // Do nothing. ASP.NET is redirecting.
}
catch(Exception ex)
  {
    // Log other exceptions.
}
  4)    Write your own custom redirect function like the one shown below
               Private void Redirect(string url, bool hasErrored)
                {
                If (hasErrored)
             {
                  HttpContext.Current.Response.Redirect(url, False)
                HttpContext.Current.ApplicationInstance.CompleteRequest()
            }
            Else  {
                  HttpContext.Current.Server.ClearError()
                HttpContext.Current.Response.Redirect(url, False)
                HttpContext.Current.ApplicationInstance.CompleteRequest()
            }
        }
    
  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.
    
Note: Images used on this website are either a production of Bhaktivedanta Book Trust(https://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 for more.

Share this to your friends. One of your friend is waiting for your share.
Related Articles
How to encode and decode HTML request in ASP.NET
Get Set Value of any HTML element using jquery-Val function
What is Silverlight,its features and how it works
Jquery features, Advantages and disadvantages
How Silverlight works internally
Calling silverlight methods from javascript
Uploading file asynchronously using Ajax AsyncFileUpload control
Working with canvas in silverlight
JQuery FAQ and Jquery Effects
Show Update Progress Animation-Ajax

Post Comment