InitializeCulture change language of domain

邮差的信 提交于 2019-12-25 09:49:40

问题


I have a MasterPage with a combo with languages, the thing is that I would like to assign a default language the moment a user starts the application, after that the user can change between languages. What I understand is that I have to override InitializeCulture method on all of the pages, the problem is, where I can save the selected language? When I use Cache["Culture"] all of the user that starts the application shares the same Cache and overrides the value for all the users logged in.

How can I do that? or how can I save data for a single user's thread when it's not logged in?

Thanks in advance for any help.


回答1:


use the Session object for data specific to sessions, if you need to persist the choice beyond the session you will need to store it with whatever user data you have

Session["Culture"] = yourculturevar;



回答2:


If you want to save information locally to a user's computer (as opposed to saving something in a database on the server for logged in users), you can use cookies.

Setting a Cookie

private void SetLanguageCookie(string language)
{
    HttpCookie cookie = new HttpCookie("UserSelectedLanguage", language);
    // Optionally set expiration for cookie
    cookie.Expires = DateTime.Now.AddDays(30);
}

Retrieving a Cookie

private string GetLanguageCookie()
{
    HttpCookie cookie = Request.Cookies["UserSelectedLanguage"];
    return cookie.Value;
}


来源:https://stackoverflow.com/questions/3760557/initializeculture-change-language-of-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!