Re: where to set the current culture in ASP.NET 2.0?
- From: "Phillip Williams" <Phillip.Williams@xxxxxxxxxxxx>
- Date: Sun, 15 Jan 2006 20:06:02 -0800
If you add Culture="auto" UICulture="auto" to the page directive and an
American user logs when his/her browser setting is “en-US” then they would
not need to select the language of their preference unless they want to
switch to a language that is not in the first selection in their browser
setting. You can then add a link that says “Select language of preference”
which would save the selection in a cookie and upon next visit the master
page would simply execute Page.Culture=selectedCulture if there were a
cookie. This would last longer than using the Session object which expires
when the browser is closed or the Session expired (in which scenario the user
has to select the culture upon every visit)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Edge" wrote:
> hi Phillip,
> because for example, in a chinese cybercafe I want a american user to login
> in our system and be able to choose his preferred language just once and
> then this selection to be applied in all the other pages.
> I tried your suggestion but, I do not want to put in every single page code
> like Page.Culture = "en-us".
>
> -E
>
>
>
>
> "Phillip Williams" <Phillip.Williams@xxxxxxxxxxxx> wrote in message
> news:433466A6-D313-4ACC-A9E9-E073B38C24EB@xxxxxxxxxxxxxxxx
> > Why not use the user's browser settings upon each postback instead? You
> > can
> > set Culture="auto" UICulture="auto" on the page directive, e.g.:
> > http://www.webswapp.com/CodeSamples/aspnet20/AutoCulture.aspx
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Edge" wrote:
> >
> >> hi,
> >> I am saving the user selected culture in a session variable so I can
> >> apply
> >> it back to all pages when refreshed and then load the proper .resx
> >> values.
> >> For that I am using global.asax, Application_AcquireRequestState, because
> >> every page load will execute this method.
> >> Even thou it works, very often I get en exception telling that the
> >> session
> >> can not be retrieved in this context.
> >>
> >> What's the best place to actually place this verification in order to be
> >> reflected in every page of my application?
> >> here the global.asax code
> >>
> >> public void Application_AcquireRequestState(object sender, EventArgs e)
> >> {
> >>
> >> if ( Session["myculture"] != null )
> >> {
> >> string currentCulture = (string)Session["myculture"];
> >> if (String.Compare(currentCulture,
> >> System.Threading.Thread.CurrentThread.CurrentCulture.ToString(),
> >> StringComparison.OrdinalIgnoreCase) != 0)
> >> {
> >> try
> >> {
> >> System.Threading.Thread.CurrentThread.CurrentCulture
> >> =
> >> System.Globalization.CultureInfo.CreateSpecificCulture(currentCulture);
> >> }
> >> catch
> >> {
> >> System.Threading.Thread.CurrentThread.CurrentCulture
> >> =
> >> new System.Globalization.CultureInfo("en-us");
> >> }
> >> System.Threading.Thread.CurrentThread.CurrentUICulture =
> >> System.Threading.Thread.CurrentThread.CurrentCulture;
> >> }
> >> }
> >> }
> >>
> >>
> >>
>
>
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: Membership Configuration Issues
- Next by Date: Re: Posting data and reading it
- Previous by thread: Re: where to set the current culture in ASP.NET 2.0?
- Next by thread: Re: where to set the current culture in ASP.NET 2.0?
- Index(es):
Relevant Pages
|
Loading