I have an ASP.NET MVC application which returns 404 and occasionally, 500 status codes at various, appropriate points.
Response.StatusCode = (int)HttpStatusCode.NotFound;
When I set one of these status codes, I also set the TrySkipIisCustomErrors property appropriately.
Response.TrySkipIisCustomErrors = true
What I would like to do now, is configure IIS to pass through these errors, which I am setting myself, and catch any other errors that may occur (such as 404s on static files, where I am not sending requests to ASP.NET, or uncaught 500 errors in my application (where presumably the TrySkipIisCustomErrors propety will not have been set by the framework).
My system.webServer/httpErrors node looks like this:
<httpErrors existingResponse="Auto" errorMode="Custom">
</httpErrors>
This returns my own ASP.NET errors where I set TrySkipIisCustomErrors = true, and the standard IIS error pages for uncaught 500s, static file 404s etc.
I then tried modifying it like this:
<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="/Skins/Shared/Error/Error.html" defaultResponseMode="ExecuteURL">
<clear />
</httpErrors>
I believe that this should display my custom error page in place of the standard IIS one. However, when I add this code I get a one line IIS error ("The page cannot be displayed because an internal server error has occurred.") and it returns a 500 status code.
I assume this is due to an error in my configuration, but I can't for the life of me understand what I'm doing wrong!
I have also tried this approach, with the same results:
<httpErrors existingResponse="Auto" errorMode="Custom" defaultPath="Skins\Shared\Error\Error.html" defaultResponseMode="File">
<clear />
</httpErrors>
Even setting a redirect to a completely different URL produces the same problem.
I have been using this page among others for reference: http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx.
The error file definitely exists, and I am able to hit it directly using a browser.
As an aside, I'm not entirely sure what I should be doing with the system.Web\customErrors node. Is this an IIS6 only setting, or does it somehow relate to ASP.NET? Currently I do not include it in my web.config.