What is happening is occasionally at random instead of the HTML being returned to the browser as you would expect, it looks a little something like this:
Thread was being aborted.HTTP/1.1 200 OK
(the rest of the header)
… (like 1/10th of the HTML)
That’s it, they are literally getting a bunch of text in the browser window.
It doesn’t happen all the time, just randomly. Computers… in my experience always have a reason for everything, ALWAYS. So what’s the heck is going on here?
I have searched the entire solution and found quite a few calls to Response.Redirect() which seems like it could be the culprit based on other questions I have read…
this is all well and good but it does not tell me why it would be happening at random
…or why it would be giving this strange result back to the browser rather than the normal custom error page we have setup. If this is indeed what is causing it, which I have not yet determined. If it is, I don’t think I can simply add the ‘false’ parameter because I don’t know what that would do if it kept executing the current code.
When you call Response.End (which is called by other methods like Response.Redirect and Server.Transfer) the executing thread is aborted and a ThreadAbortException is thrown (aborting threads are not exceptional in ASP.NET). You can catch this exception but it will always be rethrown in the
catchhandler. This sets it apart from other exception types but it makes sense because you should not be able to stop a thread from aborting and in the process clean up the stack by executing finally blocks.Perhaps you have some exception handling logic where
Response.Endis called inside atryblock and the unexpected output is produced in thecatchblock?Something like this (probably more convoluted and hard to track in a “mature” code base):
If the
Response.Redirectends withResponse.EndaThreadAbortExceptionis thrown and theResponse.Writewill execute adding text to the response.