简体   繁体   中英

ASP.NET Identity record user registration and last logged on time

I'm migrating an ASP.NET website from the old Membership provider to ASP.NET Identity 2

I noticed that user registration and last logged on time are not recorded with the new provider. Is there a way to customizing the code to do that?

To capture registration date and last login date you'll need to extend user object:

public class ApplicationUser : IdentityUser
{
     public virtual DateTime? LastLoginTime { get; set; }
     public virtual DateTime? RegistrationDate { get; set; }

    // other properties
}

And then on user creation, you'll have to populate RegistrationDate field. And on every successful login you'll have to update LastLoginTime .

And no, Identity does not support these fields automatically, you'll have to work around your requirements yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM