0

I have searched SO up and down and still getting this error. I cannot, for the life of me understand why.

{"The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:\r\n~/Views/Administrator/Error.aspx\r\n~/Views/Administrator/Error.ascx\r\n~/Views/Shared/Error.aspx\r\n~/Views/Shared/Error.ascx\r\n~/Views/Administrator/Error.cshtml\r\n~/Views/Administrator/Error.vbhtml\r\n~/Views/Shared/Error.cshtml\r\n~/Views/Shared/Error.vbhtml"}

This is caught a custom error logging class:

internal static class _Logger
{
    internal static void Log(Exception ex)
    {
        string logPath = HttpContext.Current.Server.MapPath(@"\Log\" + DateTime.Now.Month + "_" + DateTime.Now.Year + "_log");
        File.AppendAllText(logPath,
                                    "Time:" + DateTime.Now + "\n"
                                    + ex.Message +"\n" + ex.InnerException + "\n" + ex.StackTrace);
    }
}

It is being thrown from here:

  public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

    protected void Application_Error()
    {
        var ex = Server.GetLastError(); //RIGHT HERE CATCHES IT.
        _Logger.Log(ex);
    }
}

Route Config:

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Administrator",
            url: "{controller}/{action}",
            defaults: new { controller = "Administrator", action = "Index" }
        );


        routes.MapRoute(
            name: "Trials",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Trials", action = "Index", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            name: "Error",
            url: "{controller}/{action}",
            defaults: new { controller = "Error", action = "Index"}
            );

    }

What am I missing here?

Thanks.

EDIT

I removed the custom Authorization attribute and I am STILL getting this exception thrown. What confuses me is its never hitting the Catch blocks.

EDIT 2

I went back and did a breakpoint at the the app start.

Edited above is where the exception is actually being thrown from.

Gary.Taylor717
  • 163
  • 1
  • 13

1 Answers1

1

Your routing is completely misconfigured. Optional segments act like variables - any value will work. See Why map special routes first before common routes in asp.net mvc?

The problem is happening because your Administrator route is catching every single request with 1 or 2 segments in the URL, which blocks your other routes from ever being hit.

There are many ways to fix this, but the simplest is to make at least one segment in the URL static instead of using all variables.

    routes.MapRoute(
        name: "Administrator",
        url: "Administrator/{action}",
        defaults: new { controller = "Administrator", action = "Index" }
    );


    routes.MapRoute(
        name: "Trials",
        url: "Trials/{action}/{id}",
        defaults: new { controller = "Trials", action = "Index", id = UrlParameter.Optional }
    );

    routes.MapRoute(
        name: "Error",
        url: "Error/{action}",
        defaults: new { controller = "Error", action = "Index"}
        );
NightOwl888
  • 55,572
  • 24
  • 139
  • 212