As I wrote 10 days ago, a new BlogEngine.NET release had to be made to deal with some issues found in version 1.4. It’s exactly one month since the release of the 1.4 version and a lot has been fixed, tweaked and changed.

Besides some new cool features, more than 50 work items from the issue tracker at CodePlex have been implemented. That’s a lot of modified code and the result is significant. Here’s a list of some of the changes in version 1.4.5.

One of the exiting new things is that BlogEngine.NET now is released with SQL Server, MySQL, SQLite and VistaDB scripts and databases. That makes it really easy to choose the database that suits you best if you don’t want to go with the default XML provider. And by easy I mean as easy as copying a couple of files to the bin and App_Data folder and you’re all set to go.

I know some of you have had some issues with the 1.4 release, so I really hope you’ll enjoy this new version.

Download it now

I recently had the challenge of retrieving a country based on the browser language. It was used to pre-select a country in a drop down list so the user didn’t have to. I knew it wasn’t going to be 100% accurate but probably more like 80-90%.

That’s because some people change the browser language instead of their native language and others use a non-ISO standard language. And last, some clients just don’t send language information.

It wasn’t an option to use a database that mapped IP addresses to countries, so the country had to be resolved from the browser alone.

Resolve the culture

I decided to split the functionality up into two methods. The first one resolves the CultureInfo based on the browsers language.

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;

  }

}

Resolve the country

The next method uses the ResolveCulture() method above to create a RegionInfo object. The RegionInfo contains all the country information needed such as ISO code, EnglishName, NativeName and DisplayName.

public static RegionInfo ResolveCountry()

{

  CultureInfo culture = ResolveCulture();

  if (culture != null)

    return new RegionInfo(culture.LCID);

 

  return null;

}

Now I am able to get all the culture and country/region information I need based on the browser’s language, with a margin of inaccuracy I can live with.