我有网站根结构控制器,用于在url中处理文化部分, 喜欢 mysite.com/en/controller/action/id 但对于一个特定的控制器,我不想使用文化前缀。 mysite.com/controller/action/id 我怎么能这样做? 我写了它MyRoute,但它不起作用
routes.MapRoute(
name: "MyNewRoute",
url: "MyNewRoute/",
defaults: new { controller = "MyNewRoute", action = "Data", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "MemberTransfer",
url: "en/Member/Transfer",
defaults: new { culture = "en", controller = "Member", action = "Transfer", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "ExecuteTransfer",
url: "en/Member/ExecuteTransfer",
defaults: new { culture = "en", controller = "Member", action = "ExecuteTransfer", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "",
defaults: new { culture = "en", controller = "Home", action = "Maintenance", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "HomePage",
url: "{culture}/{*pathInfo}",
defaults: new { culture = "en", controller = "Home", action = "Maintenance", id = UrlParameter.Optional }
);
答案 0 :(得分:1)
交换最后两条路线。路线从上到下进行评估,与第一个匹配一起进行,因此您希望按照添加顺序从最具体到最通用。
答案 1 :(得分:1)
您的“默认”路线会覆盖最后一条路线。尝试交换最后两条路线。
不过,你可以使用Phil Haack的方便route debugger。设置和使用非常简单(您只需在Global.asax.cs中注释/取消注释一行)。绝对必须为每个Asp.Net MVC开发人员提供工具。