Answer: Below are the steps to get user's culture at run time.
1. In the first step, you have to get the Request object’s UserLanguages property.
2. Then, you have to use the returned value with the CultureInfo class to create an object representing the user’s current culture.
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