views:

6027

answers:

5

I've made the changes outlined at http://stackoverflow.com/questions/108813/404-http-error-handler-in-aspnet-mvc-rc-5 and I'm still getting the standard 404 error page. Do I need to change something in IIS?

A: 

In IIS, you can specify a redirect to "certain" page based on error code. In you example, you can configure 404 - > Your customized 404 error page.

J.W.
+1  A: 

What I can recomend is to look on FilterAttribute. For example MVC already has HandleErrorAttribute. You can customize it to handle only 404. Reply if you are interesed I will look example.

BTW

Solution(with last route) that you have accepted in previous question does not work in much of the situations. Second solution with HandleUnknownAction will work but require to make this change in each controller or to have single base controller.

My cooice is solution with HandleUnknownAction, though.

Mike Chaliy
It looks like the problem is that the standard default route of "{controller}/{action}/{id}" catches everythgin so it doesn't get to the last route. I thought that if a controller could not be found that the next route would be evaluated.
Clearly
HandleUnknownAction only works with Actions that are not foudn. What if a route is amtched but a resulting controller can not be found? What si the best way to handle that?
Clearly
Yes this is correct, only when action is not found. You can try to combine both solutions. HandleUnknownAction for missed actions and route for missed controllers. Other possible solution is custom RouteHandler.
Mike Chaliy
Hm, RouteHandler is out of the scope. Sorry, you will not be able to do this with custom ReouteHandler.
Mike Chaliy
+1  A: 

Looks like this is the best way to catch everything.

http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc

Clearly
+5  A: 

Yet another solution.

Add ErrorControllers or static page to with 404 error information.

Modify you web.config (in case of controller).

<customErrors mode="On" >
       <error statusCode="404" redirect="/Errors/Error404/" />
</customErrors>

Or in case of static page

<customErrors mode="On" >
       <error statusCode="404" redirect="/Statis404.html" />
</customErrors>

This will handle both missed routes and missed actions.

Mike Chaliy
A: 

May be Route Handling article helps to handle asp.net routing. There is described how run required controller, model, view based on passed JSON data

Universal