我想获取最近登录的用户的列表,我如何获取最近登录的asp.net core MVC中的用户列表?
您可以创建模型类:
public class LoginEntry
{
[Key]
public string EntryID { get; set; }
public string UserID { get; set; }
public ApplicationUser User { get; set; } //represents the user who was logged
public DateTime? TimeOfLastLogin { get; set; } //time when the user logged last time
}
因此,您需要在用户记录时进行输入的一些服务:
public class LoginEntryService
{
public void DoEntry(ApplicationUser user)
{
var entry = dbcontext.LoginEntries.SingleOrDefault(e => e.UserID == userID);
if (entry == null) //if Entry for the user does not exist then create it
entry = new LoginEntry() {UserID = user.ID};
entry.TimeOfLastLogin = DateTime.UtcNow; //update the last login time
if (entry.ID == null)
dbcontext.LoginEntries.Add(entry);
dbcontext.SaveChanges();
}
}
用户从登录中登录时,您可以调用DO0方法,例如,控制器或用户存储库实例