trying to change the culture in an IHttpModule

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?
 
K

Karl Seguin [MVP]

I answered the other thread, let's keep the conversation there.

Karl
--
http://www.openmymind.net/



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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top