views:

550

answers:

2

I've set up and configured ELMAH to log all of my errors on an ASP.NET MVC project I'm working on. It will be used by a small group of users who don't need to know too much so whenever there is any sort of error (404, InvalidOperation, Y2K... anything!) I just want to show them a generic default error view with instructions to call our helpdesk and sit tight.

ELMAH is up and running fine which our helpdesk staff will use to diagnose errors and log / elevate the tickets as necessary. My problem is in getting my global error page to show. I'm using the solution posted here to ensure that ELMAH and [HandleError] play nice together.

Web.config is set up as so:

<customErrors mode="On" />

If I access http://application/Home/Index which has a LINQ error (Sequence contains no elements) then I am shown my nice, generic error view from /Shared/Error.aspx but if I try to access http://application/Fake/Broken which is a 404 then I get the usual ASP.NET

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Fake/Broken

Both errors get logged perfectly by ELMAH though.

A: 

if you are using iis 7 you might need to add this to your

<system.webServer>

section in the config file

<httpErrors errorMode="Custom" existingResponse="PassThrough" />
Subnus
This didn't seem to help.
Jedidja
+2  A: 

If you're just looking to show a generic error page, then you could specify the page itself:

<customErrors mode="On" defaultRedirect="error.htm" />

That would cause all unhandled exceptions, page not founds, etc to show your "error.htm". You can be more specific about the error codes though:

<customErrors mode="On">
  <error statusCode="404" redirect="notfound.htm"/>
</customErrors>
PabloC