我的ASP.NET MVC 5项目是多语言的,我使用文化来更改语言。
我已经定义了默认的区域性路由,如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
var _cul = CultureHelper.GetCurrentCulture() != null
? CultureHelper.GetCurrentCulture()
: ConfigurationSettings.AppSettings["WebSiteDefaultCulture"];
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
"Default",
"{culture}/{Controller}/{action}/{id}",
new {culture = _cul, controller = "Home", action = "Index", id = UrlParameter.Optional}
);
routes.MapRoute(
"Home",
"{culture}/Home/{action}/{id}",
new {action = "Index", id = UrlParameter.Optional}
);
}
因此,将仅以区域性打开网站所有页面的URL。
我想打开一些没有文化的特定网站URL。
例如,可以在不提供区域性的情况下打开此URL https://test.com/en-US/Cart/Cart/5
。
谢谢。
答案 0 :(得分:0)
解决方案是定义两个路由,带和不带文化
routes.MapRoute(
name: "DefaultWithCulture",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { culture = _cul }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { culture = _cul, controller = "Home", action = "Index", id = UrlParameter.Optional }
);