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 8596553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:42:26+00:00 2026-06-12T00:42:26+00:00

Using the blog posted here and a topic here on SO i’ve created a

  • 0

Using the blog posted here and a topic here on SO i’ve created a controller which should handle all my error pages.

In my Global.asax.cs I’ve got the following piece of code:

protected void Application_Error()
        {
            var exception = Server.GetLastError();
            var httpException = exception as HttpException;
            var routeData = new RouteData();

            Response.Clear();
            Server.ClearError();

            routeData.Values["controller"] = "Error";
            routeData.Values["action"] = "General";
            routeData.Values["exception"] = exception;
            Response.StatusCode = 500;

            if (httpException != null)
            {
                Response.StatusCode = httpException.GetHttpCode();
                switch (Response.StatusCode)
                {
                    case 403:
                        routeData.Values["action"] = "Http403";
                        break;
                    case 404:
                        routeData.Values["action"] = "Http404";
                        break;
                }
            }

            // Avoid IIS7 getting in the middle
            Response.TrySkipIisCustomErrors = true;
            IController errorsController = new ErrorController();
            HttpContextWrapper wrapper = new HttpContextWrapper(Context);
            var rc = new RequestContext(wrapper, routeData);
            errorsController.Execute(rc);
        }

My ErrorController looks like this:

public class ErrorController : BaseController
    {
        /// <summary>
        /// Returns a default view for not having access.
        /// </summary>
        public ActionResult Unauthorized()
        {
            BaseModel viewModel = new BaseModel
                                      {
                                          LoginModel = new LogonModel(),
                                          ProfessionsTopX = GetTopXProfessions()
                                      };
            return View(viewModel);
        }

        public ActionResult General(Exception exception)
        {
            return View("Exception", exception);
        }

        public ActionResult Http404()
        {
            //This line works
            //return Content("Not found", "text/plain");

            //This line presents a blank page
            return View("404","_Layout");
        }

        public ActionResult Http403()
        {
            return View("403", "_Layout");
        }

    }

And my Razor View only contains the piece of html below;

@{
    ViewBag.Title = "404";
}

<h2>404</h2>

This is a 404 page!

When I use the Return Content i’m getting a plain textoutput telling me i’m looking at a 404-page. However, I want the 404 page to fit the rest of my design, so I want to use my own Views. However as soon as I use Return View I’m getting a blank page. I expect to be missing something very obvious, but I don’t see it.

  • 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-12T00:42:27+00:00Added an answer on June 12, 2026 at 12:42 am

    I was having the same problem, and finally found the solution that worked for me. The breakthrough came when I placed a breakpoint on the errorsController.Execute(rc); line, and used ‘step into’ until I came across this exception:

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

    The exception was being swallowed, I assume because it was happening inside the Application_Error method and because I had set Response.TrySkipIisCustomErrors = true.

    After seeing this error, I quickly realized my problem was simply one of mismatched names: My controller is actually named ErrorController with no ‘s’, not ErrorsController. The problem for me was that I had set routeData.Values["controller"] = "Errors";, which is wrong. Switching it to routeData.Values["controller"] = "Error"; fixed the problem.

    Note that you won’t catch the error right away, because you directly instantiate the controller, and it won’t compile if you have that part spelled wrong. But inside the controller, calling View() will look for the view using the RouteData instance we constructed and passed to the RequestContext object. So if the controller name is spelled wrong there, MVC doesn’t know where to look for the view, and since IIS custom errors are skipped, it fails silently.

    Long story short: Check your controller and view names. I assume something similar would happen if you have the controller name correct, but the file name of the view doesn’t match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a blog application using Ruby on Rails which includes the ability
I posted a url to a blog post in a Facebook message http://www.autoblog.com/2009/06/22/we-are-all-bumblebee-beijing-transformers-fans-gather-to-celebr/ and
I am using http://blog.frankel.ch/custom-loginmodule-in-tomcat tutorial for tomcat JAASRealm.I have added below in server.xml Realm
I am using a blog site as a source for my RSS Feed. As
I'm writing a simple blog using Django, and I'm including a Python CLI script
How do you use wordpress capabilities (using wp-blog-header.php) and keep the permalinks behave? I
I am trying to create a blog using blogspot. It seems it is not
I've just recently started using Github to host my blog (using Jekyll and Liquid).
I was recently given a task to create a blog using Ruby on Rails.
In my Android app, I want to use my existing sqlite database.I followed http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

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.