Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The view 'Error' or its master was not found

I've spent a lot of time trying to figure out a workaround for this to no avail, so I thought I'd see if anyone here has an idea.

I'm using Elmah in my ASP.NET MVC3 application. I'm using the exact same code from the accepted answer in the previous link.

I also have this code in my Global.asax for displaying error pages with the correct HTTP response:

    /// <summary>
    /// The customErrors functionality provided by ASP.NET results in HTTP 302 redirects occurring which doesn't accurately reflect what the real HTTP code of the response was.
    /// This method can be used to handle specific HTTP codes without an intermediate redirect.
    /// </summary>
    protected void Application_Error() {
        var exception = Server.GetLastError();
        var httpException = exception as HttpException;
        Response.Clear();
        Server.ClearError();
        var routeData = new RouteData();
        routeData.Values["controller"] = "Error";
        routeData.Values["action"] = "Error500";
        Response.StatusCode = 500;

        if (httpException != null) {
            Response.StatusCode = httpException.GetHttpCode();
            Response.TrySkipIisCustomErrors = true;
            switch (Response.StatusCode) {
                case 403:
                    routeData.Values["action"] = "Error403";
                    break;
                case 404:
                    routeData.Values["action"] = "Error404";
                    routeData.Values["message"] = httpException.Message;
                    break;
                case 500:
                    routeData.Values["action"] = "Error500";
                    break;
            }
        }

        IController errorsController = new ErrorController();
        var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
        errorsController.Execute(rc);
    }

The problem occurs when I'm not on my (local) development machine (which initially made me think it was customErrors related). When an exception is thrown, Elmah handles the error and logs it correctly. I also end up on the correct error page. However, before ending up on the correct error page, I can see another intermediate exception being logged:

The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Articles/Error.aspx ~/Views/Articles/Error.ascx ~/Views/Shared/Error.aspx ~/Views/Shared/Error.ascx ~/Views/Articles/Error.cshtml ~/Views/Articles/Error.vbhtml ~/Views/Shared/Error.cshtml ~/Views/Shared/Error.vbhtml

ASP.NET is trying to load up a default error page even though I am trying to handle it. Does anyone have any ideas on how to prevent this?

like image 854
Justin Helgerson Avatar asked Apr 17 '12 21:04

Justin Helgerson


4 Answers

Don't call the base.OnException(context); method in your custom error handler that derives from HandleErrorAttribute. You no longer need it because you have implemented a custom error handling in Application_Error.

like image 194
Darin Dimitrov Avatar answered Nov 03 '22 09:11

Darin Dimitrov


I was having this same issue, but i wasn't executing base.OnException() anywhere. Another possible solution was to remove this from <system.web> in my web.config:

<customErrors mode="On" />
like image 30
josh-sachs Avatar answered Nov 03 '22 09:11

josh-sachs


If you use Elmah.MVC and want to use custom error pages, just change the below value to true in your Web.config:

<add key="elmah.mvc.disableHandleErrorFilter" value="true" />

This will keep Elmah logging enabled but stop it from trying to redirect to the default error page.

like image 4
CapnChaos Avatar answered Nov 03 '22 09:11

CapnChaos


Somewhere your site is trying to navigate to ~/Error and it can't find it because it doesn't exist.

Trying removing or disabling customErrors in your Web.config. I'm willing to be its set to the default of on and redirect to ~/Error

If you want to post your Web.config (omitting any sensitive information) I can probably help. I've dealt with similar issues with Elmah recently.

like image 3
Terry Avatar answered Nov 03 '22 08:11

Terry