【发布时间】:2013-12-11 13:36:01
【问题描述】:
尝试为我当前的 mvc 项目设置本地化。 我需要配置路由以支持这两个 url:有和没有语言(例如 www.domain.com/en/about/contacts 和 www.domain.com/about/contact)。默认语言的 URL 中没有 lang 的路由。
我这样定义路线
routes.MapRoute(
name: "Localization",
url: "{lang}/{controller}/{action}/{identifier}",
defaults: new { lang = defaultLang, controller = "Home", action = "Index", identifier = UrlParameter.Optional }
);
但我无法满足一项重要要求 - 我的默认语言路由在 URL 中应该是“无语言”,直到用户指定所需的语言。即使该语言 == defaultLanguage 我需要我的路线包含它(语言),因为它是由用户选择的。
【问题讨论】:
标签: asp.net-mvc localization asp.net-mvc-routing