views:

27

answers:

1

I have implemented Elmah in one of my ASP.NET MVC projects. In addition I did the following:

  • I implemented the ElmahHandleErrorAttribute written by Atif Aziz in this post
  • I added the attribute to all my controllers
  • I have setup Elmah to filter out 404 errors since I do not want to log those
  • I added an Error.aspx view in the Shared folder that I wish to use for all my errors.
  • My customErrors in the Web.Config are turned on and I have not specifed any error pages in it as I shouldn't have to.

In one of my controllers I have the following code:

if (model == null)
            throw new HttpException((int)HttpStatusCode.NotFound, "Project not found");

I simply want to display a 404 if a record can not be found in the database. For some reason my Error.aspx page will not display for a 404 error. Instead it displays the generic asp.net "the resource can not be found" page. I have tried to remove the 404 filter setup in Elmah but that does not change anything.

The interesting part is if I change the error from NotFound to say InternalServerError the Error.aspx page shows up just fine.

Does anyone have any pointers as to why this is?

A: 

I have not used Elmah beyond creating a sample app - but maybe because a 404 is not application error? If my understanding is correct, a 404 error gets pushed back to IIS which in turn displays the error message you are seeing. Also, I believe that the web.coin

If i understand correctly, you may want to amend your approach and build use this instead or set the Response.StatusCode to 404 (Check out Jeff's answer in the linked question)

Ahmad