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 9 3912
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_Acq uireRequestStat e, 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_Acq uireRequestStat e(object sender, EventArgs e)
{
if ( Session["myculture"] != null )
{
string currentCulture = (string)Session["myculture"];
if (String.Compare (currentCulture ,
System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(),
StringCompariso n.OrdinalIgnore Case) != 0)
{
try
{
System.Threadin g.Thread.Curren tThread.Current Culture =
System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture);
}
catch
{
System.Threadin g.Thread.Curren tThread.Current Culture =
new System.Globaliz ation.CultureIn fo("en-us");
}
System.Threadin g.Thread.Curren tThread.Current UICulture =
System.Threadin g.Thread.Curren tThread.Current Culture;
}
}
}
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/...toCulture.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_Acq uireRequestStat e, 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_Acq uireRequestStat e(object sender, EventArgs e) {
if ( Session["myculture"] != null ) { string currentCulture = (string)Session["myculture"]; if (String.Compare (currentCulture , System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(), StringCompariso n.OrdinalIgnore Case) != 0) { try { System.Threadin g.Thread.Curren tThread.Current Culture = System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture); } catch { System.Threadin g.Thread.Curren tThread.Current Culture = new System.Globaliz ation.CultureIn fo("en-us"); } System.Threadin g.Thread.Curren tThread.Current UICulture = System.Threadin g.Thread.Curren tThread.Current Culture; } } }
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" <Ph************ **@webswapp.com > wrote in message
news:43******** *************** ***********@mic rosoft.com... 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/...toCulture.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_Acq uireRequestStat e, 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_Acq uireRequestStat e(object sender, EventArgs e) {
if ( Session["myculture"] != null ) { string currentCulture = (string)Session["myculture"]; if (String.Compare (currentCulture , System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(), StringCompariso n.OrdinalIgnore Case) != 0) { try { System.Threadin g.Thread.Curren tThread.Current Culture = System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture); } catch { System.Threadin g.Thread.Curren tThread.Current Culture = new System.Globaliz ation.CultureIn fo("en-us"); } System.Threadin g.Thread.Curren tThread.Current UICulture = System.Threadin g.Thread.Curren tThread.Current Culture; } } }
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=se lectedCulture 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" <Ph************ **@webswapp.com > wrote in message news:43******** *************** ***********@mic rosoft.com... 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/...toCulture.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_Acq uireRequestStat e, 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_Acq uireRequestStat e(object sender, EventArgs e) {
if ( Session["myculture"] != null ) { string currentCulture = (string)Session["myculture"]; if (String.Compare (currentCulture , System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(), StringCompariso n.OrdinalIgnore Case) != 0) { try { System.Threadin g.Thread.Curren tThread.Current Culture = System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture); } catch { System.Threadin g.Thread.Curren tThread.Current Culture = new System.Globaliz ation.CultureIn fo("en-us"); } System.Threadin g.Thread.Curren tThread.Current UICulture = System.Threadin g.Thread.Curren tThread.Current Culture; } } }
hi Phillip,
Thanks for the reply.
I should not put this in a cookie, some browsers/users might not
support/want it and I decided not to used. So I load a session variable with
the user language that I get from the DB after his login.
Right now, this is working in my global.asax file, but I get an exception
(but the application won't break) when the user hits the first page, than
after that is all good.
So...the problem still persists, how can I set the current culture for a
logged user without having to set in every single page the page culture?
-E
"Phillip Williams" <Ph************ **@webswapp.com > wrote in message
news:0B******** *************** ***********@mic rosoft.com... 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=se lectedCulture 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" <Ph************ **@webswapp.com > wrote in message news:43******** *************** ***********@mic rosoft.com... > 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/...toCulture.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_Acq uireRequestStat e, >> 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_Acq uireRequestStat e(object sender, EventArgs >> e) >> { >> >> if ( Session["myculture"] != null ) >> { >> string currentCulture = (string)Session["myculture"]; >> if (String.Compare (currentCulture , >> System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(), >> StringCompariso n.OrdinalIgnore Case) != 0) >> { >> try >> { >> >> System.Threadin g.Thread.Curren tThread.Current Culture >> = >> System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture); >> } >> catch >> { >> >> System.Threadin g.Thread.Curren tThread.Current Culture >> = >> new System.Globaliz ation.CultureIn fo("en-us"); >> } >> System.Threadin g.Thread.Curren tThread.Current UICulture >> = >> System.Threadin g.Thread.Curren tThread.Current Culture; >> } >> } >> } >> >> >>
In the AcquireRequestS tate stage, the SessionStateMod ule attempts to extract
the session ID from the request and retrieve the session data for that
session ID. You would get the error message "Session State is not available
in this Context" if the SessionStateMod ule failed in this process.
You can verify this info by creating a blank solution with one page marked
with EnableSessionSt ate="false" in the page directive and place your code in
the gloabl.asax.
So if you are setting the culture using the Session object, make sure that
none of your webpages (or the web.config settings) disables the Session state
otherwise your code in the global.asax will continue to catch that exception.
The web.config can also disable the Session state like this:
<configuratio n>
<system.web>
<pages enableSessionSt ate="false" />
</system.web>
</configuration>
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Edge" wrote: hi Phillip,
Thanks for the reply. I should not put this in a cookie, some browsers/users might not support/want it and I decided not to used. So I load a session variable with the user language that I get from the DB after his login. Right now, this is working in my global.asax file, but I get an exception (but the application won't break) when the user hits the first page, than after that is all good.
So...the problem still persists, how can I set the current culture for a logged user without having to set in every single page the page culture?
-E
"Phillip Williams" <Ph************ **@webswapp.com > wrote in message news:0B******** *************** ***********@mic rosoft.com... 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=se lectedCulture 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" <Ph************ **@webswapp.com > wrote in message news:43******** *************** ***********@mic rosoft.com... > 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/...toCulture.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_Acq uireRequestStat e, >> 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_Acq uireRequestStat e(object sender, EventArgs >> e) >> { >> >> if ( Session["myculture"] != null ) >> { >> string currentCulture = (string)Session["myculture"]; >> if (String.Compare (currentCulture , >> System.Threadin g.Thread.Curren tThread.Current Culture.ToStrin g(), >> StringCompariso n.OrdinalIgnore Case) != 0) >> { >> try >> { >> >> System.Threadin g.Thread.Curren tThread.Current Culture >> = >> System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(curre ntCulture); >> } >> catch >> { >> >> System.Threadin g.Thread.Curren tThread.Current Culture >> = >> new System.Globaliz ation.CultureIn fo("en-us"); >> } >> System.Threadin g.Thread.Curren tThread.Current UICulture >> = >> System.Threadin g.Thread.Curren tThread.Current Culture; >> } >> } >> } >> >> >>
I have recently done the same thing in 2.0. We have custom
implementation of the Membership provider. The MembershipUser has been
extended to support various custom properties. One is the culture
name. When the user logs in, the culture is associated with their
login id. In the page (or if you create a base page and derive your
pages from it making it even easier) override the "protected virtual
void InitializeCultu re ()" method and pull from the membership user
first putting the value in the session variable. The initializecultu re
is called very early in the pages lifecycle so your controls should
render the correct culture.
Regards
Coleman
hi michael,
in fact I just started doing this, I am creating a page base for that. but I
won't use the membership provider or profile object.
Meanwhile I will do some more research in the global.asax file, there must
be something in there:)
TIA
-E
<mi************ **@gmail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com... I have recently done the same thing in 2.0. We have custom implementation of the Membership provider. The MembershipUser has been extended to support various custom properties. One is the culture name. When the user logs in, the culture is associated with their login id. In the page (or if you create a base page and derive your pages from it making it even easier) override the "protected virtual void InitializeCultu re ()" method and pull from the membership user first putting the value in the session variable. The initializecultu re is called very early in the pages lifecycle so your controls should render the correct culture.
Regards Coleman
Edge - Try adding a handler to the following PostAcquireRequ estState
event in the global.asax. From the doc's:
HttpApplication .PostAcquireReq uestState Event
Note: This event is new in the .NET Framework version 2.0.
Occurs when the request state (for example, session state) that is
associated with the current request has been obtained.
Regards
Coleman This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Manu |
last post by:
I have created a new culture :
Dim objCulture As New CultureInfo("he") //hebrew
When I tried to assign it to the current thread.
Thread.CurrentThread.CurrentCulture = objCulture
Thread.CurrentThread.CurrentUICulture = objCulture
This Caused an exception :
|
by: Mark Kamoski |
last post by:
Hi Everyone--
Please help.
How can one get the name of the current project and the current class?
This is the situation.
Suppose there is a project called "P1".
|
by: James P. |
last post by:
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the current date. If not, I'd
like to display the error message to ValidationSummary.
It seems to make sense to me to use CompareValidator but the problem
is put the current date into CompareValidator. So, I created a hidden
text field in my aspx. ...
|
by: Stephanie Stowe |
last post by:
Imagine that I had this
<webServices>
<soapExtensionTypes>
<add type="Microsoft.Web.Services.WebServicesExtension,
Microsoft.Web.Services, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" priority="1" group="0" />
</soapExtensionTypes>
</webServices>
|
by: cmrchs |
last post by:
Hi,
I try to obtain the current culture of a server by executing :
string str = Thread.CurrentThread.CurrentCulture.ToString();
Executing this in a console-applicastion results in the correct string (e.g. "en-AU")
but when executing in ASP.NET does the command always return "en-US" ???
How come ?
| |
by: Greg Allen |
last post by:
I have a web service and am trying to use WSE 2.0 to pass attachments. I
have
enabled both the checkboxes in the WSE properties page in VS.
The problem occurs when I try to get the ResponseSoapContext in my service
to add the attachment.
Dim Context As SoapContext = ResponseSoapContext.Current
Dim Attachment As New DimeAttachment(Type, "text/html", Bytes)
Context.Attachments.Add(Attachment)
|
by: Joseph Geretz |
last post by:
Why isn't the ASP.NET runtime providing a valid reference for this object to
my WebService? I'm trying to use WSE and DIME to send attachments via Web
Service. I've provided a whole lot of information in the thread below:
DIME: Attachments.Add - Object reference not set to an instance of an
object.
Bu when all is said and done, the crux of the problem is that
ResponseSoapContext.Current = <undefined value> when I attempt to access it....
|
by: adi |
last post by:
Hi
I'm using .NET Framework 1.1
My application needs to read the system's language settings.
How to do this?
Thanks.
|
by: tamirmalas |
last post by:
Hi,
iam trying to set a culture info different than the current culture info on the system, the code compiles fine, but nothing happens, and the system culture is the one used for the program.
here is the code :
//////////////////////
CultureInfo ci = new CultureInfo("ar-SA"); // arabic Saudi Arabia
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |