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 }
);
标签:c,asp-net-mvc,asp-net-mvc-routing,asp-net-mvc-areas 来源: https://codeday.me/bug/20190702/1352495.html