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

Sign in to queue

Description

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:

C4FNews

The Discussion

Add Your 2 Cents