views:

1324

answers:

3

I want to be able to capture the exception that is thrown when a user requests a non-existant controller and re-direct it to a sweet 404 page. How can I do this?

For example, the user requests http://www.nosite.com/paeges/1 (should be/pages/) they get re-directed to the 404 rather than the nasty exception screen of death?

+4  A: 

Take a look at this page for routing your 404-errors to a specified page.

Espo
+1  A: 

Just use a route:

// We couldn't find a route to handle the request.  Show the 404 page.
routes.MapRoute("Error", "{*url}",
    new { controller = "Error", action = "404" }
);

Since this will be a global handler, put it all the way at the bottom under the Default route.

Dale Ragan
Is this right? Because sure if I define a route for {controller}/{action}/{id} lets say, and the user enters the url with a controller that doesn't exist then it will yellow-screen as that first route will match and your catch all will never be reached?
jmcd
+1  A: 

Found this on the same site - Strategies for Resource based 404s

jmcd