Jan 9, 2009

The order of route is important in asp.net mvc

I have try to add route to reroute the default.aspx to home handler.

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

routes.MapRoute("default.aspx", "default.aspx", new { controller = "Home", action = "Index", id = "" });

It throw an exception "The controller for path '/default.aspx' could not be found or it does not implement IController.". Why, it turns out the order of adding route is important. I should put my routing of "default.aspx" on top of "{controller}/{action}/{id}".