Search Mallstuffs

Flag Counter
Spirituality, Knowledge and Entertainment




Latest Articles


Move to top
Response.Redirect throws _Thread was being aborted_
Posted By Sarin on Nov 18, 2012     RSS Feeds     Latest Hinduism news
10413 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(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 for more.

Share this to your friends. One of your friend is waiting for your share.

Related Articles
Get Set Value of any HTML element using jquery-Val function
Simple Ajax client server Example
What is Silverlight,its features and how it works
Show Update Progress Animation-Ajax
Increase performance of your website using caching
How Silverlight works internally
How to encode and decode HTML request in ASP.NET
Ways of implementing AJAX
Jquery features, Advantages and disadvantages
Calling silverlight methods from javascript

Post Comment




Software developer by profession,
Poet by hobby,
Blogger by Passion
Birth Place: Munger, Bihar
Residence: Mumbai, Maharashtra
Prof exp: 8 years

Read More about me

Read my daily what'sapp quotes
Most Viewed Articles

Latest Spiritual Videos


Latest Funny Videos

Latest News

Latest Social Post
Latest WhatsApp Quotes