Tuesday, 18 March 2008

DateTime format & globalization problems in ASP.Net

Some problems cropped up recently on a project relating to datetime formats and globalisation. At first glance it seemed that it was related to en-US and en-GB datetime format conflicts. However, it was difficult to figure out why with the machine being setup in the English en-GB globalisation settings?! Turns out that an explicit globalization attribute in the apps config is required to ensure the culture setting is en-GB:

<-- Perhaps something worth adding into the frameworks web.config for all apps? -->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB"/>

This means that dispite the machine being setup in an English en-GB globalisation, .Net was reverting to en-US because nothing was explicitly set.

After a quick Google-woogle, some techie in a forum suggests a way you can force the ASP.Net user to use the system's globalisation settings as follows:

Open up the regional and language settings and navigate to the Advanced tab. Tick the check box which says "Default User Account Settings" and then reboot your server. The culture selected in the regional and language settings should now be picked up by your ASP.Net application.

I haven't tried this yet, but as soon as I get a chance I'll let you know how it goes.

No comments: