First I looked into a problem I had since the last new version of my travelog website. When I add a new entry for the day, the date and time is send along with the other data to the server with an http post. But every time I save a entry the time is reduced by 7 hours. So after a few edits even the day itself is wrong. I can explain the 7 hours, that the time difference between where I am (Peru) and the server (Germany), but where does it come from?
I looked at the database server and it has the time as specified in the web form. So the issue is getting the data back from the server. I checked my JavaScript which pulls the data via AJAX from the server and puts it onto the form, that looked fine too. Then I used Firebug to look at the JSON data that comes from the web server. The time there is seven hours less than whats in the database! I use ASP.NET web methods to return an object serialized as JSON.
The JSON serializer figures out, the client is 7 hours behind the server and takes those seven hours off each DateTime value. How does the server even know about those seven hours. I first thought about the http request headers but there is no time zone information in there. Well I still don´t know how it knows.
To fix the problem I send the timezoneOffset in the browser available through the JavaScript getTimezoneOffset() method when making a request. On the server I find out the time zone offset of the server and then fix all DateTime fields before sending them down. Not nice but it works.
getTimezoneOffset()
// get a local time zone info TimeZoneInfo tz = TimeZoneInfo.Local; // get it in hours int offset = tz.BaseUtcOffset.Hours; // add one hour if we are in daylight savings if (tz.IsDaylightSavingTime(DateTime.Now)) { offset++; }
The second problem I had was with a very simple site, I added an aspx page to download zip files from the site and log the downloads. It worked fine locally but on the live server the line:
if (System.IO.File.Exists(fileName)
Remember Me
a@href@title, b