Reputation:
Weirdly, this works locally but when it's deployed to an Azure website it doesn't
The POST
variables that fail on Azure are:
name=Test&venue=1&fromDate=26%2F06%2F14&toDate=01%2F07%2F14&eventType=1
If I POST the following it works:
name=Test&venue=1&eventType=1
So it must be something to do with the date format.
The data type on the request is a DateTime
, if I set this to string it works - I can then call request.ConvertTo<Model>
and everything is passed over as expected. I just don't want to set the fromDate and toDate to be strings on the request.
Does anyone know why this would fail?
Upvotes: 1
Views: 409
Reputation: 21501
That looks like a globalization issue. The Azure servers will be using en-US
culture that expects the dates in mm/dd/yy
format for parsing.
But you are using UK date format dd/mm/yy
, so the culture is en-GB
. Your development machine will be set to use the en-GB
locale already, hence no problems when testing locally.
You can specify the culture in your web.config
:
<configuration>
<system.web>
<globalization uiCulture="en-GB" culture="en-GB" />
</system.web>
</configuration>
Or you can do so at runtime in global.asax
:
public void PreRequestHandlerExecute(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
}
Or you could modify how ServiceStack.Text deserializes DateTime
, but I wouldn't recommend that approach. In the AppHost
Configure
method:
JsConfig<DateTime>.DeSerializeFn = date => DateTime.ParseExact(date, "dd/MM/yy", CultureInfo.InvariantCulture);
Hope that helps.
Upvotes: 2