2
votes

I am trying to set up http custom error pages in my MVC 3 web application. I have added the following to my web.config:

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteUrl" defaultPath="/Error/404">
  <clear />
  <error statusCode="500" path="/Error/404"
</httpErrors>

When a 500 error occurs on a request I expected this to redirect the user my.domainname.com/Error/404.

I have an Error controller which contains one action called error, I have mapped requests for 404 to this action.

When I force a 500 error (verified by chrome developer tools network tab) on the website I receive a blank page with the following message:

"The page cannot be displayed because an internal server error has occurred."

If I remove the httpErrors section from my web.config then I get the actual exception message. Therefore the httpErrors section I have in the web.config must be working, I just do not understand how to set it up correctly.

Here is a list of the attributes I have picked and why:

errorMode="Custom": So that I can see the custom error page and verify it is working before changing it to local only.

defaultResponseMode="ExecuteUrl": This should allow me to specify a server relative url as the path, which sounds like what I want as I want to hit a controller action.

defaultPath="/Error/404": The relative url I want requested if I do not specify one.

Edit:

I should add that the site is running on IIS 7.5. I also do not wish to use the tag as this is designed to work with IIS 6 and should be used for IIS 7+.

2

2 Answers

0
votes

Try using the customErrors section in the web.config (inside system.web) instead.

http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx

e.g.

<customErrors mode="On">
        <error statusCode="404" redirect="Error/404" />
        <error statusCode="500" redirect="Error/500" />
    </customErrors>
0
votes

It should be like Controller/Action/Id. In your case Action is missing. Check following example and change it as per your action methods...

<system.web>
    <customErrors mode="On" defaultRedirect="/Error/Index/" >
      <error statusCode="401" redirect="/Error/NoAccess/" />
      <error statusCode="404" redirect="/Error/NotFound/" />
    </customErrors>
    ....
</system.web>