views:

50

answers:

0

I have a ASP.NET web application that implements a custom Membership Provider. Because the LastLockOutDate property of the MembershipUser cannot be null, but my underlying entity does allow nulls, I was setting it like this:

DateTime lastLockOutDate = 
    (account.DateLastLockOut.HasValue) ?
        account.DateLastLockOut.Value : new DateTime();

The code for this is in a separate component to the website.

In the website I had the following to check whether the DateTime value was defaulted:

MembershipUser u = Membership.GetUser();
this.DateLastLockOut.Text =
    (u.LastLockoutDate == new DateTime()) ?
        "Unknown" : u.LastLockoutDate.ToString("D");

Oddly, I saw the following results:

u.LastLockoutDate = {01/01/0001 00:00:00}
new DateTime() = {01/01/0001 01:00:00}

In other words, the code inside the component took the time zone into consideration, but the website did not.

Is there specifically something with regards to the configuration that might be doing this? Although the following provides a workaround, I am concerned that I might get other date issues because of this.

this.DateLastLockOut.Text =
    (u.LastLockoutDate.ToUniversalTime() == new DateTime().ToUniversalTime()) ? 
        "Unknown" : u.LastLockoutDate.ToString("D");

Ta.