views:

89

answers:

2

Hi,

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?

+1  A: 

In case someone else has the same problem: The solution is to add a httpErrors element to the system.webServer section:

<httpErrors>
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/Error/FileNotFound" responseMode="ExecuteURL" />
</httpErrors>

In Windows 2008 R2, this can also be done via the IIS control panel (see "Error Pages").

Adrian Grigore
+1  A: 

See http://stackoverflow.com/questions/2480006/what-is-the-difference-between-customerrors-and-httperrors

Also see http://msdn.microsoft.com/en-us/library/ms690576.aspx

customErrors pertains to ASP.Net. httpErrors is new to IIS7 ( which you are using in both instances I'm assuming ).

The problem is most likely related you your IIS Pipeline mode. Maybe your production might be running in IIS Classic Pipeline Mode?

EDIT

It's the other way around. In Integrated Pipeline mode, the customErrors tag is not used.

kervin
Both site's app pools run in Integrated mode. Thanks for the links though, it's indeed helpful to know the difference between httpErrors and customErrors.
Adrian Grigore