Saturday, July 21, 2007

Globalization Culture : Adjust to current culture at run time

Adjusting to Current Culture at Run Time: Thread.CurrentCulture

By default, web applications run on the server using a neutral culture
When a culture attribute is set in web.config, ASP.net assigns that culture to all the the threads running for that web application
Threads are basic unit to which the server allocates processor time
ASP.net maintains multiple threads for a web application within the aspnet_wp.exe worker process
Culture can be set at runtime using the Thread class’ CurrentCulture property

Code Listing: Culture change using Thread

using System.Globalization;
using System.Threading;

private void Page_Load(object sender, System.EventArgs e)
{
sLang = Request.UserLanguages[0];
Thread.CurrentThread.CurrentCulture = new CultureInfo(sLang);
}

No comments:

Post a Comment