System.Threading.ThreadAbortException
Hi,
I often get the following exception on my SiteFinity website (version 5.4.4020.0):
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
at System.Web.HttpResponseWrapper.RedirectPermanent(String url, Boolean endResponse)
at Telerik.Sitefinity.Web.RouteHelper.SslRedirectIfNeeded(HttpContextBase httpContext, PageSiteNode node)
at Telerik.Sitefinity.Web.PageRouteHandler.ValidateCacheOutput(HttpContext context, Object data, HttpValidationStatus& status)
at System.Web.Caching.OutputCacheModule.OnEnter(Object source, EventArgs
eventArgs)
Hi Gérald,
Thanks for using our services!
This is an error stemming from Response.End not being executed. There are some resources online indicating that this may be stemming from some specific of the event not getting executed at the right event or possibly from the URL that is being constructed. I think it's the latter is true in our case, since this i. The first thing that you would need to check is what is the setting under Settings -> Advanced -> System -> Site Settings and see if Enable Non Default settings is checked or not. Make sure that SSL and the urls are configured properly according to the documentation.
The second thing that we would need to check is which URL is the redirect being issued to and checking if this url works on SSL
Just to clarify the context of troubleshooting this issue: here is a bit more elaboration on why I am thinking those settings are where the issue is coming from:
A quick look at the stack trace tells me that this is coming from the route helper (Telerik.Sitefinity.Web.RouteHelper.SslRedirectIfNeeded) responsible for redirecting to an SSL page if this is required. Therefore it's safe to assume that this exception occurs only for pages where the checkbox "Require SSL" is set on pages.
The logic of the method within the route helper is the following: if a page requires SSL then an HTTPS url is constructed and redirected to. There are two ways that Sitefinity can construct the url for HTTPS depending on settings
Hi,
I still get this error on my server so I look at your code (with reflector) and I can see "RedirectPermanent(url, true)" which throws ThreadAbordException (http://stackoverflow.com/questions/2777105/why-response-redirect-causes-system-threading-threadabortexception). So I think that the error comes from your code.
Can you confirm ?
public
static
bool
SslRedirectIfNeeded(HttpContextBase httpContext, PageSiteNode node)
...
httpContext.Response.RedirectPermanent(url,
true
);
...
Hello Gérald,
Yes it is coming exactly from this method, and it seems like it is related to configuration of SSL and therefore the constructed URL is not being passed correctly for some reason which we need to troubleshoot.
Do you have SSL enabled and configured on your site. Do any of your pages require SSL and what is the configuration there? Make sure to follow these instructions on your SSL config and double check any of the details. Also can you try opening fiddler and navigating to a page that requires SSL to see exactly what kind of behavior gets triggered there and where is the redirect issued to?
Thank you!
Regards,
Hi,
Some pages requires SSL, and some others don't.
My main issue is that I cannot reproduce the error; When I browse my website, everything works as expected and I don't have any error. But the fact are we get this error at least ten times a day (we save errors in Application_Error).
Enable Non Default settings is not checked.
[quote]The second thing that we would need to check is which URL is the redirect being issued to and checking if this url works on SSL[/quote]
I don't have this information. In Application_Error I can only get those information (+ the stacktrace)
App Domain App Id: "******"
App Domain App Path : "******"
App Domain App Virtual Path : "/"
Using Integrated Pipeline : "True"
By you could try with those urls :
http://www.softfluent.com
www.softfluent.com/shopping-cart
I don't find this error in the sitefinity log files.
Did you find a solution to this? I am getting this error as well on 6.2.4910.
It'd be nice if this were fixed. It's still happening in at least 7.1.
Hi,
I found a work around for this in December of 2013, after a long conversation with Telerik Support. In the end they could reproduce this on their end as well. They said my work around was the way to solve it, but they would talk to the developers anyway. I don't know the outcome of that. In case you contact support, tell them to look into support ticket 762668 for details.
In the end I wrote a recap about this issue:
"Internally, Sitefinity is using Response.End in their Page Route Handler. For example, this occurs when redirecting from https to http. Response.End throws a ThreadAbortException by design. This exception needs to be ignored.
Response.End only seems to throw an exception if:
a) Sitefinity is configured to redirect from https to http for pages that need to be served via http but requested through https;
b) output caching is enabled;
c) the user is anonymous.
d) the user navigates from a https to a http page for the second time.
Projects without an Application_Error event in global.asax may not notice the exception at all."
The work around is to ignore the error in the Application_Error event in global.asax:
If
(
TypeOf
(LastException)
Is
System.Threading.ThreadAbortException)
Then
Server.ClearError()
Else
' Code to handle 404 exceptions and all other exceptions that are unexpected.
End
If
Yes, I could ignore the error. But what if it's my code that's causing a ThreadAbortException? I'd like to know about it and fix it. I suppose I could check the stack trace to see if SslRedirectIfNeeded is there. But I like the practice of doing as little logic in my Application_Error as possible. This is a benign exception, but it doesn't have to happen.
Wouldn't it be simple for Sitefinity to change their RedirectPermanent call to call ApplicationInstance.CompleteRequest() and then override the page Render and RaisePostBackEvent methods? This is how I do it when I have to do a redirect from within a try/catch.
Response.RedirectPermanent(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
IsTerminating = true; // set some flag
// This could would have to be in the codebehind of the page...
private bool IsTerminating get; set;
protected override void Render(HtmlTextWriter writer)
if (!IsTerminating)
base.Render(writer);
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
if (!IsTerminating)
base.RaisePostBackEvent(sourceControl, eventArgument);
I totally agree that if Telerik can fix this, they should. Just ignoring errors is bad practice, but it works for now. If you contact Support I suppose they can have another look into this.