ASP.NET MVC 路由不起作用

ASP.NET MVC route doesn't work

我有 2 条不同的路线:

context.MapRoute(
    "zyzzyva_default",
    "{urlTitle}",
    new { area = "zyzzyva", action = "Index", controller = "Home", urlTitle = UrlParameter.Optional }
);

第二个:

context.MapRoute(
    "Vip_default_vip_thankyou",
    "{partnername}-vip-thank-you",
    new { controller = "Vip", action = "ThankYou", partnername = "" },
    new string[] { "Web.Areas.Vip.Controllers" }
);

我去mydomain.com/aaaa-vip-thank-you应该走第二条路,但我不明白为什么要走第一条路。

第一条路线太笼统了。

路由按照注册顺序找到第一个匹配项。

更改映射顺序。

context.MapRoute(
    "Vip_default_vip_thankyou",
    "{partnername}-vip-thank-you",
    new { controller = "Vip", action = "ThankYou", partnername = "" },
    new string[] { "Web.Areas.Vip.Controllers" }
);

context.MapRoute(
    "zyzzyva_default",
    "{urlTitle}",
    new { area = "zyzzyva", action = "Index", controller = "Home",urlTitle = UrlParameter.Optional }
);