I had a similar problem when I had a custom 404 page in / Error / Missing, but it didn’t appear for static files that did not exist, or for folders / directories that had DIDs (but should not be served by MVC). The controller for the Missing page has the following:
Response.AddHeader("Content-Type","text/html; charset=utf-8"); Response.TrySkipIisCustomErrors = true; Response.StatusCode = (int)HttpStatusCode.NotFound;
Also, I did not get my own error page if I returned the following to the controller:
return HttpNotFound();
I can change the default IIS errors to a blank page if I installed PassThrough:
<httpErrors existingResponse="PassThrough" />
Changing it to Replace, IIS errors returned by default.
I also had a section in my web.config, but I took it since IIS 8.5, it no longer looks like it.
<system.web> <customErrors mode="Off"> </system.web>
So basically I could not get rid of the default IIS messages - single line or more verbose. The httpErrors section is as follows:
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> <remove statusCode="404" /> <error statusCode="404" path="/Error/Missing" /> </httpErrors>
Finally, I came across this question, and I looked at another answer on this question and realized that I could try ResponseMode for each line of errors. I thought this would not be necessary since I have the defaultResponseMode parameter set, but that matters !!
So, if you want to serve a custom 404 page, use this httpErrors module:
<httpErrors errorMode="Custom"> <remove statusCode="404" /> <error statusCode="404" path="/Error/Missing" responseMode="ExecuteURL" /> </httpErrors>
I have posted all these details here so that, I hope, it seems that someone else is looking for the same thing as I, I hope this helps!