L
Lloyd Dupont
I'm trying to write a multilingual web site where the user could choose his language explicitely.
I have 2 flag, the user could click on the flag to change the culture.
The core of the logic goes in an HttpModule:
===========
public class LangModule : IHttpModule
{
public void Dispose() {}
public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;
CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
===========
However that doesn't seems to work, when page are loaded they are Page.Culture is always en-AU.
Any idea why is it so?
I have 2 flag, the user could click on the flag to change the culture.
The core of the logic goes in an HttpModule:
===========
public class LangModule : IHttpModule
{
public void Dispose() {}
public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;
CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
===========
However that doesn't seems to work, when page are loaded they are Page.Culture is always en-AU.
Any idea why is it so?