如何在 ASP.NET IDENTITY 中添加自定义表? [英] How to add custom table in ASP.NET IDENTITY?

查看:28
本文介绍了如何在 ASP.NET IDENTITY 中添加自定义表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Web 表单应用程序上使用 ASP.NET Identity.以下是我当前的身份表:

I'm using ASP.NET Identity on my web form application. Below is my current identity tables:

 - Role
 - User
 - UserClaim
 - UserLogin
 - UserRole

我需要添加一个新表来存储其他信息.

I need to add a new table to store additional information.

新表中的字段:

  • 用户登录 ID (PK)
  • 用户 ID (FK)
  • IP 地址
  • 登录日期

如何添加这个自定义表格?我知道如何在现有表中添加自定义字段,但我不知道如何实现.

How can I add this custom table? I know how to add custom fields inside existing table but I don't know how to achieve this.

感谢您为解决我的问题所做的努力.

I appreciate your efforts in reaching a solution for my problem.

推荐答案

public class ApplicationUser : IdentityUser
{

    public virtual ICollection<UserLog> UserLogs { get; set; }

}

public class UserLog
{
    [Key]
    public Guid UserLogID { get; set; }

    public string IPAD { get; set; }
    public DateTime LoginDate { get; set; }
    public string UserId { get; set; }

    [ForeignKey("UserId")]
    public virtual ApplicationUser User { get; set; }
}

public System.Data.Entity.DbSet<UserLog> UserLog { get; set; }

这篇关于如何在 ASP.NET IDENTITY 中添加自定义表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆