Coffeehouse Thread

1 post

How to make custom error pages work in ASP.NET MVC 4?

Back to Forum: Coffeehouse
  • User profile image
    Sathyaish Chakravarthy

    I want a custom error page shown for 500, 404 and 403. Here's what I have done:

    1) Enabled custom errors in the web.config as follows:


    <customErrors mode="On"
          <error statusCode="403"
            redirect="~/Views/Shared/UnauthorizedAccess.cshtml" />
          <error statusCode="404"
            redirect="~/Views/Shared/FileNotFound.cshtml" />

    2) Registered HandleErrorAttribute as a global action filter in the FilterConfig class as follows:

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
                filters.Add(new CustomHandleErrorAttribute());
                filters.Add(new AuthorizeAttribute());

    3) Created a custom error page for each of the above messages. The default one for 500 was already available out of the box.

    4) Declared in each custom error page view that the model for the page is System.Web.Mvc.HandleErrorInfo

    For 500, it shows the custom error page. For others, it doesn't.

    Is there something I am missing?

    It does look like this is not all there is to displaying custom errors as I read through the code in the OnException method of the HandleErrorAttribute class and it is handling only 500.

    What do I have to do to handle other errors?

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.