0

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?

1 Answer 1

0

You need to change the 404 page at the site level.

Open the IIS snap-in.

Drill down to your site on the left side.

Then on Error Pages (right side, second section), edit the 404 page so that it directs to your custom page.

You should be all set then.

2
  • @Dayton: I can see how I could use that to redirect to my own page, but the problem is that I actually want it to use the error handling that I've already set up (in my Application_Error). If I do as you suggest, then all my logging, etc. would have to be replicated there. And I'd end up with different behaviour from my (Cassini) development server, which is likely to be a headache. Can I somehow tell IIS to let me handle all errors and not stick its oar in? Apr 14, 2010 at 11:42
  • Bummer. You may want to repost to StackOverflow. This could be better solved over there. Apr 14, 2010 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .