• February 2010
    M T W T F S S
    1234567
    891011121314
    15161718192021
    22232425262728
  • Latest Posts

  • Latest Comments

  • Archives

Globalization in web.config

Technorati Tags: ,,

Headline: Putting the following code in the web config (at least for an ASP.NET MVC app) will cause your pages to honor the user’s browser settings.

Code Snippet
  1.   <!–If culture and uiCulture are set to auto, ASP.NET can set the UI culture and culture for a Web page automatically, based on the values that are sent by a browser.–>
  2.   <globalization culture="auto:en-US" uiCulture="auto:en"/>
  3. </system.web>

I got the idea from the following post:

But when I ran tests and looked at the Microsoft documentation, the enableClientBasedCulture is not used at this time (not even in .NET 4.0):

http://stackoverflow.com/questions/1633980/asp-net-mvc-when-to-set-thread-currentthread-currentuiculture

However, the thread did send me in the right direction. So now if a user sets their language for Internet Explorer:

Tools –> Internet Options

image

Then Languages:

image

In the example above, the preferred language is en-GB (Great Britain English) which will display dates in dd/mm/yyyy order. When I display a web page today (5 Feb 2010) I can see this:

image

When this was in the Site.Master:

Code Snippet
  1. [<%= System.Globalization.CultureInfo.CurrentUICulture.Name %>] <%= DateTime.Today.ToShortDateString() %>

Works great! 

Leave a Comment