November Happy Hour will be moved to Thursday December 5th.

Unexpected error handling. Hides the real error.

Vote:
 

We are having an issue right now where when an error is thrown from a controller, it is trying to route the error to an error page that does not exist. In turn this error is handled by our own custom handling with the customErrors web config and logging to our sql server logs.

This is the error that gets logged:

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

It should not be trying to use this 'Error' page as we have not configured it to do so. This is an issue as this error and not the real error gets logged.

See our config for errors:

Web Config

<customErrors mode="On">
      <error statusCode="404" redirect="/page-not-found" />
      <error statusCode="500" redirect="/server-error" />
</customErrors>

<httpErrors errorMode="Custom" existingResponse="PassThrough">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/page-not-found" responseMode="ExecuteURL" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="500" path="/server-error" responseMode="ExecuteURL" />
</httpErrors>

<!-- Global error handling is turned off so it should be using our own defined error handling -->
<episerver>
    <applicationSettings globalErrorHandling="Off" httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" />
</episerver>

And our handler for errors to log to SQL

protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();
            LogManager.GetLogger().Log(Level.Error, "Unhandled error occurred", exception);            
        }

Of course we can turn off custom errors for development, but we need this for better error logging in our production enviornment.

Thanks for any help

#211441
Jan 08, 2020 16:01
Vote:
 

Hi Brian, it is unclear from your post if you have registered the required route for your custom 500 and 404 (what controller will handle that), the httpErrors section custom error? Currently in your web.config you say for IIS errors 500 and 404 execute custom URL, but do you have a route registered for these paths?

For example you could override the Global.asax.cs RegisterRoutes method like this to register the controller(s) for your custom errors:

protected override void RegisterRoutes(RouteCollection routes)
        {
            // extension method signatur: name, url template, object to define the controller and action which will handle it

            routes.MapRoute("404", "page-not-found", new { controller = "SiteError", action = "NotFound" });
            routes.MapRoute("500", "server-error", new { controller = "SiteError", action = "InternalError" });

            base.RegisterRoutes(routes);
        }

So then your error controller would have the chance to handle the exception or page not found.

If you don't have the above now, the error you are logging is naturaly the last unhandled exception which is the view is not found.

If you have the route registration to your custom 404/500 controller, then check that your action is trying to execute the correct action and returning the correct view (as it now looks a view is returned which is not found). So maybe your action is trying to return wrong view or the path to the view is incorrect.

#215933
Jan 19, 2020 10:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.