Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
Which version of IIS is running on your server? –  counsellorben Nov 4 '11 at 15:56

3 Answers 3

up vote 2 down vote accepted

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>
share|improve this answer

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.

share|improve this answer
    
I'll find out and get back to you –  AJH Nov 4 '11 at 17:06
    
Official response: "You mean the application pool? We dont use classic mode. it is intergrated" –  AJH Nov 4 '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 - MSFT Nov 5 '11 at 4:11

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?

share|improve this answer
    
Yep that would be it... but I see the aspx files in the proper directory on the server. What gives? –  AJH Nov 4 '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 4 '11 at 15:52
    
Yeah that doesn't sound good. What version of IIS are you running? –  simonlchilds Nov 4 '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 4 '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 5 '11 at 2:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.