Use the Profile class to store and set the UI culture

原创 2004年09月21日 18:58:00
 

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 that stage.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

The Profile feature uses an HttpModule (ProfileModule) to get the profile data for the current user or the default value specified in the web.config.

 

The ProfileModule will make the Profile class available when the Application’s AcquireRequestState event is executed. The AcquireRequestState is executed on each request of a page.

 

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 support of anonymous users, the default value specified for the properties of the profile will be available for the anonymous user at the AcquireRequestState event.

 

The following is a simple example that will demonstrate the use of the Profile class and the AcquiredRequestState event to set the UI culture on each request:

 

Web.config:

 

<?xml version="1.0"?>

<configuration>

   <system.web>

      <authentication mode="Forms" />

         <profile>

                      <properties>

                         <add name="Culture" defaultValue="en-US" type="System.String" allowAnonymous="true"/>

                      </properties>

          </profile>

      <anonymousIdentification enabled="true"/>

   </system.web>

</configuration>

 

As you can see in the web.config above there is a default value for the Culture property. When the use is not authenticated the default value specified for the Culture property will be used to set the UI culture.

 

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";

}

github在eclipse上的插件egit官方使用指南

转自:http://wiki.eclipse.org/EGit/User_Guide EGit/User Guide EGit Contents  [h...
  • shanliangliuxing
  • shanliangliuxing
  • 2013年02月04日 16:10
  • 20337

Android Lint 检查规则列表

英文原文: http://tools.android.com/tips/lint-checks 这里的Android Lint所检查规则列表是从ADT21中得来的默认的,在Android S...
  • qq_29134495
  • qq_29134495
  • 2016年05月24日 09:30
  • 1454

App 提交到App Store上的各种状态

Viewing and Changing Your App’s Status and Availability When your app is available on the store, ...
  • yuanya
  • yuanya
  • 2014年04月25日 09:24
  • 8775

Using the context-level DFD developed a Sales System for a computer store, develop level 1 and level 2 data flow diagrams. Use a “grammatical parse” on the context-level processing narrative to get yourself started remember to specify all information

  • 2008年12月21日 19:30
  • 336KB
  • 下载

ZipStorer - A Pure C# Class to Store Files in Zip

  • 2009年09月05日 12:57
  • 82KB
  • 下载

A neat way to use MFCs built in serialization to store COM o

  • 2006年02月23日 09:05
  • 8KB
  • 下载

WPF A view model base class to use with MVVM in WPF

  • 2009年08月10日 12:02
  • 5KB
  • 下载

How to Use 'Group By' in Class in Salesforce

How to Use 'Group By' in class? 1.Construct new Class public class SummaryObject{ //create new...
  • u010093998
  • u010093998
  • 2015年07月18日 22:38
  • 189

Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications

转:http://msdn.microsoft.com/zh-cn/magazine/cc301786(en-us).aspx   John Hind Code ...
  • sx811125
  • sx811125
  • 2012年05月03日 14:27
  • 856

Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications

Serial Comm Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications Joh...
  • dnvodcwan
  • dnvodcwan
  • 2012年03月29日 21:27
  • 291
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Use the Profile class to store and set the UI culture
举报原因:
原因补充:

(最多只允许输入30个字)