0

In my ASP.NET MVC project I have the /errors/error.html page as a general error page and a second /errors/error404.aspx that handles the 404 errors.

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/errors/error.html">
    <error statusCode="404" redirect="/errors/error404.aspx" />
</customErrors>

Also, I have in my Global.asax file a general handler that logs all uncaught exceptions for logging purposes.

public void Application_Error(object sender, EventArgs e)
{
    Exception ex = Server.GetLastError();
    Common.Core.LogError(ex); // Saving exception details in the database
}

The above setup works well except for when I have a general error (e.g. a 500 error) the Application_Error logs this error below:

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

The Exception from the actual error is not logged at all.

How can I avoid this error?

P.S. For anyone who might ask, I tried to put my error pages as views inside a controller but also I couldn't make it work with the redirectMode="ResponseRewrite" option.

1 Answer 1

3

You are trying to handle errors in a non-ASP.NET MVC way, in an ASP.NET MVC project. To resolve your issue, you could comment the line filters.Add(new HandleErrorAttribute()); in the FilterConfig.cs file. See the snippet below.

public class FilterConfig
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        //filters.Add(new HandleErrorAttribute());
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, that made it work! Yes, I realized that I was a bit away from the MVC way, but the MVC way seemed a bit of overkill at the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.