Oi, Hello, Hola, Hoi, Konnichiwa and Ahoy Mattie!

1142624605_localization_wsis_2006[1] Mads Kristensen, of BlogEngine.Net fame, has a post on getting the language and country from a browser in ASP.Net.  Why is this important?  Well, some sites have something called localization/internationalization and mapping IP addresses to countries isn't always the best option.

Here is some of the Culture code:

public static CultureInfo ResolveCulture() 
{ 
  string[] languages = HttpContext.Current.Request.UserLanguages; 

  if (languages == null || languages.Length == 0) 
    return null; 

  try 
  { 
    string language = languages[0].ToLowerInvariant().Trim(); 
    return CultureInfo.CreateSpecificCulture(language); 
  } 
  catch (ArgumentException) 
  { 
    return null; 
  } 
}

The country code can be found by reading his post!

Tag:

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.