我有一个具有多语言功能的网站。我仍然使用cookie来检测语言,例如,如果用户选择“英文”,那么我会将cookie值更改为“EN”并向用户提供“英文页面”。MVC中的多语言支持
我想更改此行为并从URL而不是cookie中读取语言。因此,例如,如果产品页面当前URL是
www.ezstore.com/product/asus-gtx970
我想要的网址更改为
www.ezstore.com/en/product/asus-gtx970 for english
www.ezstore.com/fr/product/asus-gtx970 for french
我想改变RouteConfig
和读取URL来获得语言的价值。这可能吗?
我现在RouteConfig
是:
routes.MapRoute("Product", "Product/{id}", new {
controller = "Product",
action = "Index",
id = UrlParameter.Optional
});
routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
我会考虑使用浏览器发送的HTTP_ACCEPT_LANGUAGE头。这是用户喜欢的语言。 –
看看[this](http://www.wiliam.com.au/wiliam-blog/web-design-sydney-using-mvc-routing-for-seo-friendly-urls-on-multilingual-sites)文章。 –
我认为这是你需要的答案[http://stackoverflow.com/questions/1712167/asp-net-mvc-localization-route#answer-1712320](http://stackoverflow.com/questions/1712167/asp -net-mvc-localization-route#answer-1712320) –