1

在我的应用程序中,我有一些使用特定路由的控制器和一些使用默认路由的控制器。结果,我有这样的事情:

//.. 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" }
 );

但是,如果我键入类似 ~/Home/SomethingThatDoesntExist 的内容,它将被默认路由器拾取,因此永远不会到达我的包罗万象的路由处理程序。我已经通过 Phil Haack 的路由调试器验证了这一点。结果,它将尝试访问该控制器/动作并且找不到它。作为回报,StructureMap 会抛出一个错误,该错误会冒泡到 Application_Error 我无法重定向的地方(尽管我已经尝试过一切并通过研究)。

那么,无论如何,我是否必须为我的所有控制器和操作指定特定的路由,一旦我在 Application_Error() 中,如何重定向到特定的页面/控制器?

4

0 回答 0