Board index » Web Programming » trying to change the culture in an IHttpModule

trying to change the culture in an IHttpModule

Web Programming322
This is a multi-part message in MIME format.



------=_NextPart_000_0232_01C61470.38996EF0

Content-Type: text/plain;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



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:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

public class LangModule : IHttpModule

{

public void Dispose() {}



public void Init(HttpApplication application)

{

HttpContext context =3D application.Context;

HttpCookie lc =3D context.Request.Cookies[LangCookieName];

if (lc =3D=3D null)

return;



CultureInfo ci =3D new CultureInfo(lc.Value);

Thread.CurrentThread.CurrentCulture =3D ci;

Thread.CurrentThread.CurrentUICulture =3D ci;

}

public static string LangCookieName =3D "UserSelectedLanguage";

public static void SetLocale(HttpContext context, CultureInfo =

locale)

{

if (locale =3D=3D null)

return;

HttpCookie lc =3D new HttpCookie(LangCookieName, locale.Name);

lc.Expires =3D DateTime.Now.AddDays(360);

context.Response.Cookies.Add(lc);

Thread.CurrentThread.CurrentCulture =3D locale;

Thread.CurrentThread.CurrentUICulture =3D locale;

}

}

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

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?



--=20

I have taken a vow of poverty. If you want to really piss me off, send =

me money.



------=_NextPart_000_0232_01C61470.38996EF0

Content-Type: text/html;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=3DContent-Type content=3D"text/html; =

charset=3Diso-8859-1">

<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>

<STYLE></STYLE>

</HEAD>

<BODY>

<DIV>I'm trying to write a multilingual web site where the user could =

choose his=20

language explicitely.</DIV>

<DIV>I have 2 flag, the user could click on the flag to change the=20

culture.</DIV>

<DIV>The core of the logic goes in an HttpModule:</DIV>

<DIV>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>

<DIV><FONT size=3D2><FONT color=3D#0000ff>public</FONT><FONT=20

color=3D#0000ff>class</FONT><FONT color=3D#008080>LangModule</FONT>: =

</FONT><FONT=20

size=3D2><FONT color=3D#008080>IHttpModule<BR></FONT>{<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT =

color=3D#0000ff>void</FONT>=20

Dispose() {}<BR><BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =

public</FONT><FONT=20

color=3D#0000ff>void</FONT>Init(<FONT =

color=3D#008080>HttpApplication</FONT>=20

application)<BR>&nbsp;&nbsp;&nbsp; {<BR><FONT =

color=3D#008080>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; HttpContext</FONT>context =3D =

application.Context;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HttpCookie</FONT>=

lc =3D=20

context.Request.Cookies[LangCookieName];<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if</FONT>(lc =

=3D=3D <FONT=20

color=3D#0000ff>null</FONT>)<BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =



&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return</FONT>;<BR><BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CultureInfo</FONT>=

ci =3D=20

<FONT color=3D#0000ff>new</FONT><FONT=20

color=3D#008080>CultureInfo</FONT>(lc.Value);<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentCulture =3D ci;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentUICulture =3D =

ci;<BR>&nbsp;&nbsp;&nbsp;=20

}<BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT=20

color=3D#0000ff>static</FONT><FONT color=3D#0000ff>string</FONT>=

LangCookieName =3D=20

<FONT color=3D#800000>"UserSelectedLanguage"</FONT>;<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT =

color=3D#0000ff>static</FONT>=20

<FONT color=3D#0000ff>void</FONT>SetLocale(<FONT =

color=3D#008080>HttpContext</FONT>=20

context, <FONT color=3D#008080>CultureInfo</FONT>=

locale)<BR>&nbsp;&nbsp;&nbsp;=20

{<BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

if</FONT>(locale=20

=3D=3D <FONT color=3D#0000ff>null</FONT>)<BR><FONT =

color=3D#0000ff>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

return</FONT>;<BR>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; <FONT color=3D#008080>HttpCookie</FONT>lc =3D <FONT=20

color=3D#0000ff>new</FONT><FONT =

color=3D#008080>HttpCookie</FONT>(LangCookieName,=20

locale.Name);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lc.Expires =3D =

<FONT=20

color=3D#008080>DateTime</FONT>.Now.AddDays(360);<BR>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; context.Response.Cookies.Add(lc);<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentCulture =3D locale;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentUICulture =3D =

locale;<BR>&nbsp;&nbsp;&nbsp;=20

}<BR>}<BR></FONT>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>

<DIV><FONT face=3DArial size=3D2>However that doesn't seems to work, =

when page are=20

loaded they are Page.Culture is always en-AU.</FONT></DIV>

<DIV><FONT face=3DArial size=3D2>Any idea why is it so?</FONT></DIV>

<DIV><FONT face=3DArial size=3D2></FONT><BR>-- <BR>I have taken a vow of =

poverty. If=20

you want to really piss me off, send me money.<BR></DIV></BODY></HTML>



------=_NextPart_000_0232_01C61470.38996EF0--


-
 

Re:trying to change the culture in an IHttpModule

This is a multi-part message in MIME format.



------=_NextPart_000_0019_01C61448.6E645DB0

Content-Type: text/plain;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



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



Karl

--=20

www.openmymind.net/">www.openmymind.net/







"Lloyd Dupont" <net.galador@ld>wrote in message =

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:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

public class LangModule : IHttpModule

{

public void Dispose() {}



public void Init(HttpApplication application)

{

HttpContext context =3D application.Context;

HttpCookie lc =3D context.Request.Cookies[LangCookieName];

if (lc =3D=3D null)

return;



CultureInfo ci =3D new CultureInfo(lc.Value);

Thread.CurrentThread.CurrentCulture =3D ci;

Thread.CurrentThread.CurrentUICulture =3D ci;

}

public static string LangCookieName =3D "UserSelectedLanguage";

public static void SetLocale(HttpContext context, CultureInfo =

locale)

{

if (locale =3D=3D null)

return;

HttpCookie lc =3D new HttpCookie(LangCookieName, locale.Name);

lc.Expires =3D DateTime.Now.AddDays(360);

context.Response.Cookies.Add(lc);

Thread.CurrentThread.CurrentCulture =3D locale;

Thread.CurrentThread.CurrentUICulture =3D locale;

}

}

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

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?



--=20

I have taken a vow of poverty. If you want to really piss me off, send =

me money.



------=_NextPart_000_0019_01C61448.6E645DB0

Content-Type: text/html;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=3DContent-Type content=3D"text/html; =

charset=3Diso-8859-1">

<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>

<STYLE></STYLE>

</HEAD>

<BODY bgColor=3D#ffffff>

<DIV><FONT face=3DArial size=3D2>I answered the other thread, let's keep =

the=20

conversation there.</FONT></DIV>

<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT face=3DArial size=3D2>Karl</FONT><BR>-- <BR><A=20

href=3D"www.openmymind.net/">www.openmymind.net/</A></DIV>">www.openmymind.net/">www.openmymind.net/</A></DIV>

<DIV>&nbsp;</DIV>

<DIV><BR>&nbsp;</DIV>

<BLOCKQUOTE dir=3Dltr=20

style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =

BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

<DIV>"Lloyd Dupont" &lt;<A =

href=3D"mailto:net.galador@ld">net.galador@ld</A>&gt;=20

wrote in message <A=20

=

href=3D"news:%235YenxBFGHA.2036@TK2MSFTNGP14.phx.gbl">news:%235YenxBFGHA.=

2036@TK2MSFTNGP14.phx.gbl</A>...</DIV>

<DIV>I'm trying to write a multilingual web site where the user could =

choose=20

his language explicitely.</DIV>

<DIV>I have 2 flag, the user could click on the flag to change the=20

culture.</DIV>

<DIV>The core of the logic goes in an HttpModule:</DIV>

<DIV>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>

<DIV><FONT size=3D2><FONT color=3D#0000ff>public</FONT><FONT=20

color=3D#0000ff>class</FONT><FONT color=3D#008080>LangModule</FONT>: =



</FONT><FONT size=3D2><FONT =

color=3D#008080>IHttpModule<BR></FONT>{<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT =

color=3D#0000ff>void</FONT>=20

Dispose() {}<BR><BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; =

public</FONT><FONT=20

color=3D#0000ff>void</FONT>Init(<FONT =

color=3D#008080>HttpApplication</FONT>=20

application)<BR>&nbsp;&nbsp;&nbsp; {<BR><FONT =

color=3D#008080>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; HttpContext</FONT>context =3D =

application.Context;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

HttpCookie</FONT>lc =3D=20

context.Request.Cookies[LangCookieName];<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if</FONT>(lc =

=3D=3D <FONT=20

color=3D#0000ff>null</FONT>)<BR><FONT =

color=3D#0000ff>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return</FONT>;<BR><BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

CultureInfo</FONT>ci =3D=20

<FONT color=3D#0000ff>new</FONT><FONT=20

color=3D#008080>CultureInfo</FONT>(lc.Value);<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentCulture =3D ci;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentUICulture =3D =

ci;<BR>&nbsp;&nbsp;&nbsp;=20

}<BR><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT=20

color=3D#0000ff>static</FONT><FONT color=3D#0000ff>string</FONT>=

LangCookieName =3D=20

<FONT color=3D#800000>"UserSelectedLanguage"</FONT>;<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; public</FONT><FONT=20

color=3D#0000ff>static</FONT><FONT color=3D#0000ff>void</FONT>=

SetLocale(<FONT=20

color=3D#008080>HttpContext</FONT>context, <FONT=20

color=3D#008080>CultureInfo</FONT>locale)<BR>&nbsp;&nbsp;&nbsp; =

{<BR><FONT=20

color=3D#0000ff>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if</FONT>=

(locale =3D=3D <FONT=20

color=3D#0000ff>null</FONT>)<BR><FONT =

color=3D#0000ff>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

return</FONT>;<BR>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; <FONT color=3D#008080>HttpCookie</FONT>lc =3D =

<FONT=20

color=3D#0000ff>new</FONT><FONT =

color=3D#008080>HttpCookie</FONT>(LangCookieName,=20

locale.Name);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lc.Expires =3D =

<FONT=20

=

color=3D#008080>DateTime</FONT>.Now.AddDays(360);<BR>&nbsp;&nbsp;&nbsp;=20

&nbsp;&nbsp;&nbsp; context.Response.Cookies.Add(lc);<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentCulture =3D locale;<BR><FONT=20

color=3D#008080>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20

Thread</FONT>.CurrentThread.CurrentUICulture =3D =

locale;<BR>&nbsp;&nbsp;&nbsp;=20

}<BR>}<BR></FONT>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>

<DIV><FONT face=3DArial size=3D2>However that doesn't seems to work, =

when page are=20

loaded they are Page.Culture is always en-AU.</FONT></DIV>

<DIV><FONT face=3DArial size=3D2>Any idea why is it so?</FONT></DIV>

<DIV><FONT face=3DArial size=3D2></FONT><BR>-- <BR>I have taken a vow =

of poverty.=20

If you want to really piss me off, send me=20

money.<BR></DIV></BLOCKQUOTE></BODY></HTML>



------=_NextPart_000_0019_01C61448.6E645DB0--



-