I’d like my ASP.NET MVC application to redirect failed requests to matching action methods of a certain controller. This works fine on my development machine running Windows 7, but not on my production machine running Windows 2008 R2.
I set up my web.config as follows:
<customErrors mode="On" defaultRedirect="/Error/ServerError/500">
<error statusCode="403" redirect="/Error/AccessDenied" />
<error statusCode="404" redirect="/Error/FileNotFound" />
</customErrors>
This customErrors section works fine on both of my machines (production and development) for 500 Internal Server errors.
It also works fine for 404 errors on my development machine.
However, it does not properly redirect 404 errors on the production machine. Instead of /Error/FileNotFound, I get the standard 404 page that comes with IIS 7.
What could be the problem here?
In case someone else has the same problem: The solution is to add a httpErrors element to the system.webServer section:
In Windows 2008 R2, this can also be done via the IIS control panel (see “Error Pages”).