Q:

IIS7 - combination of ASP.NET customErrors, IIS httpErrors

I've seen a number of similar questions to this on StackOverflow and on other sites, but nothing that seems to resolve the issue I'm experiencing.
I'm trying to configure a site to return a 500 status code and a custom error page (static HTML file) for ASP.NET errors that would normally return a 500 where customErrors is set to "Off", and 404 status code for pages that our system reports as not being found (the 404 page is not a static page set via IIS, it's generated by our CMS system).
I'm part way there, but I've hit a bit of a brick wall.
At present, I'm able to return the correct 404 status code where our system returns a page with a 404 status code, but I'm now unable to return a 500 status code for ASP.NET server errors.  I managed this by setting Response.TrySkipIisCustomErrors = true.  My 500 errors, however, are proving more complicated.  If I remove the customErrors config section from my web.config, I get the 500 error but it's the ugly ASP.NET YSOD.  I can't seem to get this to point to a custom page using IIS at all, no matter what settings I use for the httpErrors config section and no matter what I set via the IIS GUI.  If I add the customErrors section back, I get the custom error page as I'd expect, but I get a 200 or 302 error (depending on the value of redirectMode attribute).
Anyone got any ideas?
In terms of httpErrors config section I've tried the following so far:
Setting errorMode to "Custom" and specifying my static content for errors with a statusCode of "500" and a subStatusCode of "-1" (removing existing 500 error first)
Setting errorMode to "Detailed" and specifying my static content for errors with a statusCode of "500" and a subStatusCode of "-1" (removing existing 500 error first)
Setting existingResponse="PassThrough" for both configuration options above.

A:

It seems you may be going above and beyond what you need to do, that is if I understand you correctly.  Here is a good link 
It seems like you what you need is to handle the global.asax Application_Error Event.  This way you can handle it anyway you like and you dont get that ugly asp.net error screen.  Any web app I create I put some code in there to handle errors so the user wont see any unformatted "blow ups"

