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.
- <!–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.–>
- <globalization culture="auto:en-US" uiCulture="auto:en"/>
- </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):
However, the thread did send me in the right direction. So now if a user sets their language for Internet Explorer:
Tools –> Internet Options
Then Languages:
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:
When this was in the Site.Master:
- [<{f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}= System.Globalization.CultureInfo.CurrentUICulture.Name {f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}>] <{f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}= DateTime.Today.ToShortDateString() {f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f}>
Works great!
Leave a Reply