I got some questions regarding how to use the Profile class to set the current UI culture on each request of a page. In the current version of ASP.Net 1.x, we could use the BeginRequest even in global.asax to set the UI culture. By doing that all pages will use the culture specified in the BeginRequest event. This solution still works in ASP.Net 2.0. But if you have a property in the Profile class that has the culture to be set, the BeginRequest could not be Used. The profile class is not available at what stage.
. T..........
.
Note:. The AcquireRequestState will be executed after the Profile's MigrateAnonymous event So if you change the property of the Profile class in the MigrateAnuinbymouse event when a user is authenticated, the new values will be available in the AcquireRequestState event.
Instead of using the BeginRequest event you can now use the AcquireRequestState event to set the UI culture before the requested page is processed (If you want to store the user's culture into the Profile class). If the user is not authenticated and you have enabled the ...................................... ...CRIPLILE,
The Following Is A Simple Example That Will DeMonstrate The Use of the Profile Class and The AcquidrequestState Event To Set The Ui Culture on Each Request:
Web.config:
XML Version = "1.0"?>
Global.asax:
void Application_AcquireRequestState (object sender, EventArgs e) {System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo (Profile.Culture);}
The above code uses the AcquireRequestState event to set the UI culture on each request. The value form the Profile's Culture property would be the culture. As I mention before, the DeafultValue (en-US in this case) will be used if the user is Not Authenticated.
If you now authentiacte the user and set a new value to the Profile's Culture property, e.g. sv-SE for Swedish, the next request made to any of the pages in your web application will use the new Culture for the UI.
Here Is An Example Where The Culture Property Is Set After a User is Authenticated:
If (! request.isauthenticated) {Formsauthentication.SetAuthCookie ("Fredrik", False; profile.culture = "sv-se";