2
votes
  • I'm having a problem with an application on a specific server.

On every environment except the problem environment

The server correctly recognizes that all clients are in the UK and parses UK formatted dates:

DD/MM/YYYY

On the problem server

The problem only appears to happen on one server. This server seems to incorrectly require american dates:

MM/DD/YYYY

What I've tried already

  • Adding a "globalization" section to web.config file to attempt to force en-GB culture
  • Checking the "machine.config's" globalization section (it says en-GB as well).
  • I've checked that the clients are requesting en-GB as the prefered culture for the respnse.
  • At Eoin's suggestion I've also checked the regional settings for the server (they have the date set to dd/MM/yyyy which is correct).

What I cannot try

I'm using MS ASP.NET MVC which is automatically de-serializing the HTML form data into an object, so I can't manually specify the date format -- e.g. using DateTime.Parse(myDateStr, "dd/MM/yyyy") as the parsing is done by Microsoft MVC.

Is there anything else I can do. This is an intranet app, and all clients are in the UK.

5

5 Answers

5
votes

If you're overriding the current culture like that in your globalization section, make sure you specify the UICulture & Culture options.

However given that you've got this problem on only 1 out of many servers, I would expect that the server itself is configured differently. If you can log in to your problem-server as an admin, check the following (this is windows 7 but should be similar on Windows Server 2008)

Control Panel > Region & Language > Formats Tab > Format: "English (United Kingdom)"

and verify that the dates are expected in dd/MM/yyyy format

1
votes

You needs to do following two things.

  1. Set Culture in web.config as given below

    uiCulture="en-GB" culture="en-GB" .

  2. Set your form method to POST as I have mentioned below

    using (Html.BeginForm("DailyReport", "Reports", FormMethod.Post, new { id = "ActivityReport" }))
    

DailyReport is your controller action method, Reports is controller and most important thing is FormMethod.Post by setting form method to POST will solve your Date format problem.

Enjoy!

1
votes

One possible cause is the system setting of date/time format is set to US. You can check that in Region and Language in Control Panel.

enter image description here

0
votes

Your server probably runs as a different culture. If you only run one project on your server, you can change its culture like Eoin Campbell just suggested

but if your server runs other projects that are culture aware, you can just force the thread of your project into UK mode like so:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB")
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB")

Without affecting all other things running on the server

-1
votes
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");