0

I am working on a legacy website that uses MVC 3, elmah and nhibernate. The Elmah log has literally thousands of " The view 'Error' or its master was not found" errors. I assume that it is covering up the real error. I cannot figure out how to have the real error get logged by Elmah.

As a means to attempt to debug, I added - return RedirectToAction("noWhere"); - to force an error. Locally I get a .net screen that simply says "An exception occurred while processing your request..." on staging I get YOSOD screen telling me to set the web.config customerrors node. Both have the customerrors set to on.

The web config has the following:

 <pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
</pages>
<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>


  <customErrors mode="On" defaultRedirect="~/Views/Shared/PageNotFound">
      <error statusCode="404" redirect="~/Views/Shared/PageNotFound" />
      <error statusCode="500" redirect="~/Views/Shared/PageNotFound" />
  </customErrors>

The Global.asax has:

 public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
         filters.Add(new ElmahHandleErrorAttribute());
    }

The Elmah class has

public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute 
{
    public override void OnException(ExceptionContext context)         
    {             
        base.OnException(context);               
        var e = context.Exception;             
        if (!context.ExceptionHandled // if unhandled, will be logged anyhow      
            || RaiseErrorSignal(e)    // prefer signaling, if possible 
            || IsFiltered(context))   // filtered?
            return;               
        LogException(e);         
    }  

and the baseController class has:

protected ViewResult PageNotFound()
    {
        Response.StatusCode = (int)HttpStatusCode.NotFound;

        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }

    protected ViewResult PageBadRequest()
    {
        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return View("PageNotFound", PageViewModelBuilder.UpdateSiteProperties(new PageViewModel()));
    }

Any help on getting the correct errors to log would be appreciated....

user1069733
  • 485
  • 9
  • 17

1 Answers1

1

Change "~/Views/Shared/PageNotFound" to "~/Views/Shared/PageNotFound.aspx” (or "~/Views/Shared/PageNotFound.chtml”) in your web.config and make sure you have PageNotFound.aspx in your Shared folder.

StarCub
  • 4,141
  • 7
  • 41
  • 58
  • yeah, change it to that then. I have edited my answer. Did it solve your problem? Please mark as answer if it did. – StarCub Apr 01 '13 at 21:18
  • Thanks - but adding the cshtml causes a httpexception to be thrown and does not affect the original problem – user1069733 Apr 01 '13 at 21:57
  • What's the httpexception you are getting now? I think if you solve the error, elmah will only log related real erros. – StarCub Apr 01 '13 at 22:50
  • System.Web.HttpException at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute - statusCode="404" – user1069733 Apr 02 '13 at 13:55