c# – ASP.NET MVC路由不起作用

我有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-你应该使用第二条路线,但我不明白为什么它使用第一条路线.

最佳答案 第一条路线太笼统了.

路由使用第一次匹配,按照它们的注册顺序.

更改映射顺序.

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 }
);
点赞