Web server returning proper response with 500 status

Problem

I’ve had a funny problem today. It wasn’t so funny during hour time I was trying to solve it. Directing my browser to a web page which looked OK yesterday resulted in a horrific view of content without downloaded styles and smelled like missing script files.

Debugger has shown that indeed, some of the static files could not be downloaded. Status 500, server said. Internal server error, server said. Ok then, let’s see what this is about. So I open Response body and what do I see? I see proper response, from start to end.

2015-03-06_19-07-14

This happened to random static files.

Root cause

My bad…

I’ve placed some debugging code which occasionally failed in Global.asax.cs, Application_Start method. Code was such that it failed for random web request, and IIS was configured through web.config to let ASP.NET handle all requests, including static files. So, from standpoint of ASP.NET, web request has failed since an exception was thrown and it returned status 500 to IIS. However, it did not return any response body along with status, so IIS grabbed the file and sent it back.