J
JJ
I am comparing the 'lastloggedin' and 'createddate' fields of the membership
table to see if this is the first time the user has logged in.
(if they are within 1 second on each other I presume this is the first
login).
I have worked out that I can't check for this in the 'onLoggedIn' event, as
this is after the 'lastloggedin' field is updated. So, I am trying to do the
check in the 'onAuthenticate' event.
However, when I add this handler I stop the authentication taking place.
How do I let authentication take place normally whilst still running my
extra code?
Or, is there another way to check for first login?
JJ
i.e.:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
string thisUsername = ((System.Web.UI.WebControls.Login)(sender)).UserName;
DateTime CreatedDateTime = Membership.GetUser(thisUsername).CreationDate;
DateTime LastLoggedInDateTime =
Membership.GetUser(thisUsername).LastLoginDate;
System.TimeSpan TimeDiff = LastLoggedInDateTime.Subtract(CreatedDateTime);
//Probably only need 2 seconds max
if (TimeDiff.TotalSeconds < 2)
{
//this is first login
FirstLogin = true;
}
}
table to see if this is the first time the user has logged in.
(if they are within 1 second on each other I presume this is the first
login).
I have worked out that I can't check for this in the 'onLoggedIn' event, as
this is after the 'lastloggedin' field is updated. So, I am trying to do the
check in the 'onAuthenticate' event.
However, when I add this handler I stop the authentication taking place.
How do I let authentication take place normally whilst still running my
extra code?
Or, is there another way to check for first login?
JJ
i.e.:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
string thisUsername = ((System.Web.UI.WebControls.Login)(sender)).UserName;
DateTime CreatedDateTime = Membership.GetUser(thisUsername).CreationDate;
DateTime LastLoggedInDateTime =
Membership.GetUser(thisUsername).LastLoginDate;
System.TimeSpan TimeDiff = LastLoggedInDateTime.Subtract(CreatedDateTime);
//Probably only need 2 seconds max
if (TimeDiff.TotalSeconds < 2)
{
//this is first login
FirstLogin = true;
}
}