I found a problem with the above approach if the user is a superuser. There were two users with the same username in the aspnet_Membership table, one with the applicationid corresponding to an applicationname of -1 and the other with an applicationid corresponding to the portal applicationname of 0. When the user is a superuser, the applicationname is set to -1, and all user lookups look up the user entry in aspnet_Membership corresponding to this applicationname. So I deleted the record from the aspnet_Membership table with the username of the superuser that corresponded to the applicationname of 0 (the portal), leaving only the record corresponding to the superuser and the applicationname of -1, then I changed the code above as shown below. It seems to work now for my purposes. Anywhere in the app I want to use the lastlogindate, I use the Session("LastLoginDate") variable. I could not use the lastlogindate of the user object carried in the context, as this user object appears to be re-created occasionally and the lastlogindate is therefore updated to the most recent logon, whereas I wanted the most recent logon before this "session" so I could continue to display the "new" and "updated" icons until the user was done looking around (session ended).
I do not completely understand everything that occurs regarding the user stuff (why does DNN set the appname to -1 for a superuser?), and this is definitely a hack, but it appears to be working for my purposes. Hope it helps you.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
If Not CType(HttpContext.Current.Items("UserInfo"), UserInfo) Is Nothing Then
Session("LastLoginDate") =
CType(HttpContext.Current.Items("UserInfo"), UserInfo).Membership.LastLoginDate
Else
Session("LastLoginDate") =
Date.Now
End If
'Update lastlogindate
Dim objmembershipuser As MembershipUser = Microsoft.ScalableHosting.Security.Membership.GetUser(True)
If objmembershipuser Is Nothing Then
Dim OriginalApplicationName As String = Globals.GetApplicationName
'could be a SuperUser, try super user application name
Globals.SetApplicationName(Globals.glbSuperUserAppName)
objmembershipuser = Membership.GetUser
objmembershipuser.LastLoginDate =
Date.Now
Microsoft.ScalableHosting.Security.Membership.UpdateUser(objmembershipuser)
'Reset the Application Name
Globals.SetApplicationName(OriginalApplicationName)
Else
objmembershipuser.LastLoginDate =
Date.Now
Microsoft.ScalableHosting.Security.Membership.UpdateUser(objmembershipuser)
End If
End Sub