How can I stop IIS7 (integrated mode) from reporting a 404 before I get a chance to handle it?

Posted by Gary McGill on Server Fault See other posts from Server Fault or by Gary McGill
Published on 2010-04-14T10:01:50Z Indexed on 2010/04/14 10:03 UTC
Read the original article Hit count: 312

Filed under:

I have an ASP.NET MVC 2 application running on IIS7 in integrated mode. I'm trying to do my own 404 handling, but IIS7 seems to be intercepting the error and returning its own 404 message to the client before I get a chance to handle it.

I'm not having much luck coming at the problem from a programming perspective over on Stack Overflow, so I wondered if maybe it's a configuration problem. Is there something I have to do to tell IIS to let me handle my own errors? (I'm trying to use Application_Error in my global.asax but it's not even getting there).

There is a custom error page defined (at the machine level, I think) for 404 but when I tried removing that it didn't really help - it simply showed a bald one-liner message instead. My code still didn't get a look in.

Is it perhaps something to do with the routing? Maybe the "mysite.com/nosuchpage" URL isn't being routed to me and that's why I don't get a chance to intercept it? Do I need to do something so that ALL requests get routed through my app?

© Server Fault or respective owner

Related posts about iis7