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.

AJH
  • 365
  • 1
  • 4
  • 18

3 Answers3

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>
AJH
  • 365
  • 1
  • 4
  • 18
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?

Simon
  • 2,810
  • 2
  • 18
  • 23
  • Yep that would be it... but I see the aspx files in the proper directory on the server. What gives? – AJH Nov 04 '11 at 15:47
  • 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. – AJH Nov 04 '11 at 15:52
  • Yeah that doesn't sound good. What version of IIS are you running? – Simon Nov 04 '11 at 15:54
  • @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 Nov 04 '11 at 20:00
  • @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** – John Nov 05 '11 at 02:19
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.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • I'll find out and get back to you – AJH Nov 04 '11 at 17:06
  • Official response: "You mean the application pool? We dont use classic mode. it is intergrated" – AJH Nov 04 '11 at 18:08
  • 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? – Adam Tuliper Nov 05 '11 at 04:11