Response.Redirect Thread Was Being Aborted. Properly Handle this Exception and not with a Try/Catch.


Due to Response.End calls Thread.Abort.

To avoid this error you can catch for it like most people do it.

Or do it the “right” way.

Don’t call Response.End by using the overload.  Use HttpApplication.CompleteRequest() instead.

Response.Redirect(stringURL, False)HttpContext.Current.ApplicationInstance.CompleteRequest()

Unfortunately, since you’re not aborting the thread the postback finishes and the html gets sent to the client.

Found a great post on the topic here by John S. Reid, where he goes into details on the solution.  For now, here’s the final solution. I would suggest a base page. But this is what you would have on your actual page.


Private blnPageIsTerminating As Boolean = False

Protected Sub SomePageEventOrOtherMethodThatYouAreRedirectingFrom()
    Response.Redirect(UrlDocumentLink(oCurrDocument.DocumentMasterID), False)
    blnPageIsTerminating = True
End Sub

Protected Overrides Sub RaisePostBackEvent(ByVal sourceControl _
           As IPostBackEventHandler, ByVal eventArgument As String)
    If blnPageIsTerminating = False Then
        MyBase.RaisePostBackEvent(sourceControl, eventArgument)
    End If
End Sub

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
    If blnPageIsTerminating = False Then
    End If
End Sub

Hiring for an Information Architect (IA) Position. Know anyone?

Delete All Files & Folders from Parent that are older then X Days