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?