What are the steps to follow to get user's culture at run time?

 Posted by deccansoft on 10/30/2010 | Category: ASP.NET Interview questions | Views: 3249

To get the user’s culture at run time, follow these steps:
1. Get the Request object’s UserLanguages property.
2. Use the returned value with the CultureInfo class to create an object representing the user’s current culture.
For example, the following code gets the user’s culture and displays the English name and the abbreviated name of the culture in a label the first time the page is displayed:
private void Page_Load(object sender, System.EventArgs e)
{ // Run the first time the page is displayed if (!IsPostBack) { // Get the user's preferred language.
string sLang = Request.UserLanguages[0]; // Create a CultureInfo object from it.
CultureInfo CurrentCulture = new CultureInfo(sLang);
lblCulture.Text = CurrentCulture.EnglishName + ": " + CurrentCulture.Name;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response