3

I'm trying to get the custom 404 page we've built to display instead of the default 404 page created by the server. It works as intended when debugging the application locally, but not when running the application on the server. And their web.config files look exactly the same.

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

The weird thing is when anything about the is modified - setting mode to "Off" or "RemoteOnly", changing "~/Error" to just "Error", or removing the section entirely - the result is always the same: I get my nice looking 404 page locally, but not on the server.

When debugging locally, this method executes as intended:

    public class ErrorController : BaseController
    {
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult NotFound()
        {
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            ErrorSignal.FromCurrentContext().Raise(new HttpException(404, Request.Url.PathAndQuery + " was not found"));
            return View();
        }
    }

Because it found this route in Global.asax:

routes.MapRoute(
"NotFound",
"{*path}",
    new { controller = "Error", action = "NotFound" });

Any and all advice is appreciated.

1
  • 1
    Which version of IIS is running on your server? Commented Nov 4, 2011 at 15:56

3 Answers 3

3

Problem solved - I went to the guy who manages our IIS settings and had him change the Error Page path for 404s to be a redirect to a URL, that URL being "/Error/NotFound/Index.aspx". But apparently, that's just the equivalent of adding this to the system.webServer section:

<httpErrors>
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/Error/NotFound" responseMode="ExecuteURL" />
</httpErrors>
Sign up to request clarification or add additional context in comments.

Comments

1

Sounds to me like the 404 you are getting on the server is because your custom 404 can't be found. Are you able to browse to the custom 404?

5 Comments

Yep that would be it... but I see the aspx files in the proper directory on the server. What gives?
I've found an uncomfortable solution: I went to the guy who manages our IIS settings and had him change the Error Page path for 404s to be a redirect to a URL, that URL being "/Error/NotFound/Index.aspx". Which is weird because NotFound only exists as an aspx file, not as a directory that contains an Index.aspx file... but maybe that's something about how MVC works that I'm just not aware of. And it's an uncomfortable solution because he's going to have to change this on each website on the test server (we have several) as well as the QA server and the production server.
Yeah that doesn't sound good. What version of IIS are you running?
@AdamTuliper The short answer is, each of our sites has custom-built error pages designed to match the style of the site, and we want customers to see these instead of error pages generated by the server.
@AJH The reason you have to use /Error/NotFound is because of how your MVC is setup, you are using the Error Controller with the NotFound Action
0

Is your iis on the server not running in integrated mode? If so 404s will never hit asp.net What version of iis? Make sure it's not in classic mode.

3 Comments

I'll find out and get back to you
Official response: "You mean the application pool? We dont use classic mode. it is intergrated"
actually looking at this code again, I wouldn't expect your customErrors 404 to do anything here that I can see. You are stating already an unknown url is a known URL from your route, so your 404 custom errors wouldn't ever be used here. What shows on the server?

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.