Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:33:23+00:00 2026-06-15T23:33:23+00:00

I want a custom error page shown for 500, 404 and 403. Here’s what

  • 0

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" 
                  defaultRedirect="~/Views/Shared/Error.cshtml">
    
        <error statusCode="403" 
               redirect="~/Views/Shared/UnauthorizedAccess.cshtml" />
    
        <error statusCode="404" 
               redirect="~/Views/Shared/FileNotFound.cshtml" />
    
    </customErrors>
    
  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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:33:24+00:00Added an answer on June 15, 2026 at 11:33 pm

    My current setup (on MVC3, but I think it still applies) relies on having an ErrorController, so I use:

    <system.web>
        <customErrors mode="On" defaultRedirect="~/Error">
          <error redirect="~/Error/NotFound" statusCode="404" />
        </customErrors>
    </system.web>
    

    And the controller contains the following:

    public class ErrorController : Controller
    {
        public ViewResult Index()
        {
            return View("Error");
        }
        public ViewResult NotFound()
        {
            Response.StatusCode = 404;
            return View("NotFound");
        }
    }
    

    And the views just the way you implement them. I tend to add a bit of logic though, to show the stack trace and error information if the application is in debug mode. So Error.cshtml looks something like this:

    @model System.Web.Mvc.HandleErrorInfo
    @{
        Layout = "_Layout.cshtml";
        ViewBag.Title = "Error";
    }
    <div class="list-header clearfix">
        <span>Error</span>
    </div>
    <div class="list-sfs-holder">
        <div class="alert alert-error">
            An unexpected error has occurred. Please contact the system administrator.
        </div>
        @if (Model != null && HttpContext.Current.IsDebuggingEnabled)
        {
            <div>
                <p>
                    <b>Exception:</b> @Model.Exception.Message<br />
                    <b>Controller:</b> @Model.ControllerName<br />
                    <b>Action:</b> @Model.ActionName
                </p>
                <div style="overflow:scroll">
                    <pre>
                        @Model.Exception.StackTrace
                    </pre>
                </div>
            </div>
        }
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently using a custom error page for 404 errors for our Web
I have created a custom page for error messages in my web application. I
I have a website set up that uses a custom 404 error page. This
I want to display 404 error page for that i have made error404.php file
I am using .htaccess to show custom HTML page for errors (401, 404, 500
I want my page to redirect to custom error 500 page. However, when I
im trying to implement a custom error page, what i want to be able
I understand that it is possible to serve a custom Error 404 page using
My main issue is that I want to display an custom error page when
I've set up a custom error page to handle errors thrown through my site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.