Knowing that there are (at least) three APIs that internally use Thread.Abort
, I'd like to answer in more practical terms, how to work out what to do about it.
For us, this error started being logged all-of-a-sudden. What changed? We fixed a bug in some database procedure that was dealing with sitemaps.
The log4net logs showed the X-Forwarded-For header (we're behind an NLB) was Googlebot's IP address, 66.249.78.x which bolstered my theory about the sitemap change leading to Google crawling our site more aggressively looking for images.
The first thing was to find out why only the Googlebot was able to cause this problem. No other client was triggering whatever code path uses Response.Redirect
, or whatever.
So in the HttpApplication.Error
handler, I added some code to log extra detailed output with all headers, and most data in the HttpResponse
and HttpContext
spewed to log.
This let me see that the problem was that Googlebot is using an iPhone user agent string and armed with that, I was able to search the codebase for "iPhone" and come up with:
private void CheckIPhoneAccess() { ... }
And that uses a Redirect.
What to do about it?
Well, for this aged codebase, it's not worth retro-patching all the Response.Redirect
calls, so I'm going to lower the logging level for ThreadAbortException
for the application.
I will change the behaviour for Googlebot's mobile crawler, that would not lead to 'lies' about what our site serves to mobiles since it only redirects on the first hit, subsequently it reads a cookie and shows the image. Googlebot does not seem to cache that cookie.
It's not perfect, but the site is due to be rebuilt. probably by another team using Scala or something, so in practical terms, I think this is a good choice. I'll add comments and may revisit the issue later, build a Response.SafeRedirect
extension that encapsulates this advice:
Why Response.Redirect causes System.Threading.ThreadAbortException?
Luke