我有一個具有多語言功能的網站。我仍然使用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) –