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

  • Home
  • SEARCH
  • 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 8814703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:11:43+00:00 2026-06-14T04:11:43+00:00

my question is regarding Pure.Kromes answer to this post . I tried implementing my

  • 0

my question is regarding Pure.Kromes answer to this post. I tried implementing my pages’ custom error messages using his method, yet there are some problems I can’t quite explain.

a)
When I provoke a 404 Error by entering in invalid URL such as localhost:3001/NonexistantPage, it defaults to the ServerError() Action of my error controller even though it should go to NotFound(). Here is my ErrorController:

    public class ErrorController : Controller
    {
        public ActionResult NotFound()
        {
            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            var viewModel = new ErrorViewModel()
            {
                ServerException = Server.GetLastError(),
                HTTPStatusCode = Response.StatusCode
            };
            return View(viewModel);
        }

        public ActionResult ServerError()
        {
            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            var viewModel = new ErrorViewModel()
            {
                ServerException = Server.GetLastError(),
                HTTPStatusCode = Response.StatusCode
            };
            return View(viewModel);
        }
    }

My error routes in Global.asax.cs:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

        routes.MapRoute(
            name: "Error - 404",
            url: "NotFound",
            defaults: new { controller = "Error", action = "NotFound" }
            );

        routes.MapRoute(
            name: "Error - 500",
            url: "ServerError",
            defaults: new { controller = "Error", action = "ServerError" }
            );

And my web.config settings:

<system.web>
    <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/ServerError">
    <error statusCode="404" redirect="/NotFound" />
</customErrors>
...
</system.web>

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/NotFound" responseMode="ExecuteURL" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="500" path="/ServerError" responseMode="ExecuteURL" />
</httpErrors>
...

The Error views are located in /Views/Error/ as NotFound.cshtml and ServerError.cshtml.

b)
One funny thing is, When a server error occurs, it does in fact display the Server Error view I defined, however it also outputs a default error message as well saying that the Error page could not be found.

Here’s how it looks like:

Do you have any advice how I could fix these two problems? I really like Pure.Kromes approach to implementing these error messages, but if there are better ways of achieving this don’t hestitate to tell me.

Thanks!

**EDIT : **
I can directly navigate to my views through the ErrorController by accessing /Error/NotFound or Error/ServerError.

The views themselves only contain some text, no markup or anything.

As I said, it actually works in some way, just not the way I intended it to work. There seems to be an issue with the redirect in the web.config, but I haven’t been able to figure it out.

  • 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-14T04:11:45+00:00Added an answer on June 14, 2026 at 4:11 am

    I got it to work. It seems my understanding of the problem was somewhat wrong to begin with.

    In the web.config, I changed the following:

    <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Views/Error/ServerError.cshtml">
      <error statusCode="404" redirect="~/Views/Error/NotFound.cshtml" />
    </customErrors>
    

    …
    and
    …

    <httpErrors errorMode="Custom" existingResponse="Replace">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" path="/NotFound" responseMode="ExecuteURL" />
          <remove statusCode="500" subStatusCode="-1" />
          <error statusCode="500" path="/ServerError" responseMode="ExecuteURL" />
        </httpErrors>
    

    This directly redirects to the views. My understanding was that I had to redirect to the error controller which in turn would redirect to the views, but apparently this was not the case. I’d like to thank you for your comments as they have made me analyze the problem again when I was already about to just ditch the custom error stuff and simply be lazy and display YSOD’s. 🙂

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

Sidebar

Related Questions

another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
This question is challenging to get more understanding on Image Processing using pure C.
A quick question regarding the java.lang.VerifyError exception. Suppose I get an error that looks
Question regarding how to setup dbase relationships (newbie, this may be trivial) Followed the
While answering this question regarding safe escaping of filename with spaces (and potentially other
I have a question regarding EC2. Let's say I have a pure EC2 instance
Quick question regarding this Socket(String host, int port) If I use these arguments in
I have a somewhat ridiculous question regarding DDD, Repository Patterns and ORM. In this
Question regarding GtkBuilder. When we unref builder pointer does it destroys all the screens/widgets
Question regarding fluent nHibernate table mappings: Apparently I was under the mistaken impression, that

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.