This project is read-only.
1
Vote

MapDelegate overrides default routing when calling with Html.ActionLink

description

Given the following routes
routes.MapDelegate("RouteFailureTest", "home/test",
        context => new HomeController().HomeTest(context.HttpContext));

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }//, // Parameter defaults
);
a call to @Html.ActionLink("Log Off", "Logout", "User") always matches the "RouteFailureTest".

My guess is that it's related to the lack of default controller/action values so the ActionLink, providing the default values matches the delegate route.

It's fairly simple to reproduce, use a standard MVC3 application (with default Home/Account controllers) add the MapDelegate route above and check the Login/Home/About Us links. They will always match the RouteFailureTest route.

comments

BuildStarted wrote Aug 24, 2011 at 4:41 AM

        routes.MapRoute(
            "ShouldntMatch", // Route name
            "home/test", // URL with parameters
            null // Parameter defaults
        );
Confirmed it's the null defaults. This route produces the same results as the MapDelegate by matching any Html.ActionLink or other similar helpers