Try our conversational search powered by Generative AI!

Unexpected error handling. Hides the real error.


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:

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" />

<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" />

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

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

Jan 08, 2020 16:01

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" });


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.

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.