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. [<{f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}= System.Globalization.CultureInfo.CurrentUICulture.Name {f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}>] <{f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}= DateTime.Today.ToShortDateString() {f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}>

Works great! 


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.