Many classes in the .NET Framework -- and, by extension, in ASP.NET -- are culture-aware. To access this awareness, you need to create a CultureInfo object to represent the current culture and associate it with the running thread's CurrentCulture property. Once this link has been made, common functions such as String.Format and DateTime's ToShortDateString will adjust according to the culture formatting.
ASP.NET must look at the Accept-Language header of the HTTP request to determine a user's culture request. ASP.NET will expose this header as a string array under the UserLanguages property of the Request object.
Adding some code to the Global.asax file's Application_BeginRequest event will allow you to create the CultureInfo object for the correct language (see Figure 5). Once you have created the CultureInfo object for the user's primary language, it will need to be associated to the current thread processing the request.
Getting ASP.NET formatting data according to each user's culture preference might be just the first step in making your application span the global community. But in many cases, it might be the only step needed.
Imports System.Threading Imports System.Globalization Public Class Global Inherits System.Web.HttpApplication
Sub Application_BeginRequest(ByVal sender As Object, _ ByVal e As EventArgs) Try If Request.UserLanguages.Length > 0 Then Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture_ (Request.UserLanguages(0)) End If Catch 'Don't error if CreateSpecificCulture fails End Try End Sub End Class
Siva
|
No responses found. Be the first to respond and make money from revenue sharing program.
|