views:

28

answers:

2

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  A: 

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;
Pharabus
+1  A: 

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;
}
Wonko the Sane