1

In my application, I have some controllers that use specific routes and some that use the default route. As a result, I have something like this:

//.. other more specific routes
routes.MapRoute(
                "Workout - Specific Workouts by exercise",
                "{userName}/workouts/exercise/{exerciseID}/{exerciseName}",
                new { controller = "Workout", action = "WorkoutsByExercise" }
                );

            routes.MapRoute(
                "Default",                                             
                "{controller}/{action}/{id}",                           
                new { controller = "Home", action = "Index", id = "" } 
            );
            routes.MapRoute(
                "Error",
                "{*catchall}",
                new { controller = "Error", action = "Http404" }
 );

However, if I type something like ~/Home/SomethingThatDoesntExist it will be picked up by the default router and thus never gets to my catchall route handler. I've verified this through Phil Haack's route debugger. As a result, it will try to get to that controller/action and wont find it. In return, StructureMap throws an error which bubbles up to Application_Error where I can't redirect it (despite everything I've tried and through research).

So, is there anyway around this or do I have to specify specific routes for all of my controllers and actions AND how can I redirect to a specific page/controller once I'm in Application_Error()?

MunkiPhD
  • 3,636
  • 1
  • 29
  • 51
  • Check out these two SO Q&A's: http://stackoverflow.com/questions/310580/how-can-i-make-a-catch-all-route-to-handle-404-page-not-found-queries-for-asp-n http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/620559#620559 – Kevin LaBranche Sep 03 '09 at 02:21

0 Answers0