【发布时间】:2026-01-26 00:15:02
【问题描述】:
我意识到按特定顺序定义和执行路由的概念,但我定义了以下路由:
routes.MapRoute(
"Image",
"Image/{action}/{width}/{height}/{file}",
new { controller = "Image", action = "Thumbnail", width = 250, height = 250 }
);
routes.MapRoute(
"GetCampaignsByCampaignType",
"Endorsement/GetCampaignsByCampaignType/{campaignType}",
new { controller = "Endorsement", action = "GetCampaignsByCampaignType" }
);
routes.MapRoute(
"Help",
"Help",
new { controller = "Help", action = "Contact" }
);
routes.MapRoute(
"Campaigns",
"Campaigns",
new { controller = "Endorsement", action = "Campaigns" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Campaign",
"{campaignUrlName}",
new { controller = "Endorsement", action = "GetCampaign" }
);
问题与底部 2 条路线有关。我有像 /Summer、/Winter、/Some-other-name 这样的广告系列,我有数百个这样的广告系列,并且不想将它们硬编码进去。我还有其他希望受到打击的路线,例如 /Campaign/Account, /Help/Me/Please(如果有多个片段 /1/2 或 /1/2/3)
什么是正确的顺序或定义,可以让 /1 转到上面定义的最后一条路线,而 /1/2 或 /1/2/3 转到默认的 {controller}/{action}/{id}
目前,这两种情况都使用默认路由 {controller}/{action}/{id},包括 /1。如果我反转它们,那么 /1 可以工作,但 /1/2 或 /1/2/3 不会转到默认路由。
感谢任何帮助。
【问题讨论】:
标签: asp.net-mvc-3 asp.net-mvc-routing