如果我去mysite / Catalog,那就打破了。怎么解决呢?
routes.MapRoute(
"Localization", // Route name
"{lang}/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
答案 0 :(得分:2)
它会匹配你的第一条路线,认为“目录”是“lang”。您需要为本地化创建约束。
以下路线应匹配前缀为任何语言代码的请求(例如en,cs,de或en-US,en-GB ...)
routes.MapRoute("Localization", "{lang}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { lang = "[a-z]{2}(-[a-z]{2})" }
);