Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop IIS7 from putting out its own 404 before my MVC app gets a chance to handle it?

I have an ASP.NET MVC 2 application, which has an Application_Error event handler in global.asax. In this, I'm detecting the case where the Exception type is HttpException and the HTTP code is 404, and redirecting to my own 404-handling page.

This works fine on my Cassini development server, but now I'm trying to move it over to my production server which has IIS7 (using integrated mode).

When I request a non-existent URL, IIS7 is showing its own 404 page, and so far as I can tell, my Application_Error method is never called.

How do I fix that?

like image 626
Gary McGill Avatar asked Apr 13 '10 17:04

Gary McGill


2 Answers

I answered that in another post: ASP.NET Application hosted on IIS7 that is ignoring custom errors and falls back to IIS errors

"To disable the IIS error messages you have to set

  Response.TrySkipIisCustomErrors = true;

in your error page. After that, your Error messages should show without problem."

like image 124
Michael A. Volz aka Flynn Avatar answered Nov 08 '22 09:11

Michael A. Volz aka Flynn


Can't you just turn off the 404 httpError:

    <httpErrors errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1" />
    </httpErrors>
like image 38
K.Rijpstra Avatar answered Nov 08 '22 08:11

K.Rijpstra