jQuery and ASP.NET

February 15, 2009

How to Display Last Login Date for a User in ASP.NET




If you are using Forms Authentication and want to find the last login date of a registered user, here's how to do so. In the Login_Authenticate event, use the following code just before authentication the user:

C#


protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)


{


MembershipUser mu = Membership.GetUser(Login1.UserName);


DateTime dt = mu.LastLoginDate;


Session["lastlogindt"] = dt;



// Then authenticate the user here (e.Authenticate = true)


}




VB.NET


Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)


Dim mu As MembershipUser = Membership.GetUser(Login1.UserName)


Dim dt As DateTime = mu.LastLoginDate


Session("lastlogindt") = dt



' Then authenticate the user here


End Sub




'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "How to Display Last Login Date for a User in ASP.NET"
  1. Anonymous said...
    December 14, 2010 3:18 PM

    Works great!!

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions