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

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

问题描述

我用我的web表单应用程序ASP.NET身份。
下面是我当前的标识表:

当前标识表

   - 角色
  - 用户
  - UserClaim
 - 用户登录
  - UserRole的

我需要添加一个新表来存储更多的信息。

新表:UserLogs

新表内字段:


  • UserLogID(PK)

  • 用户ID(FK)

  • ip地址

  • LoginDate

我如何添加此自定义表?我知道如何添加现有表内的自定义字段,但我不知道如何来实现这一目标。

我AP preciate您在达成解决我的问题的努力。


解决方案

 公共类ApplicationUser:IdentityUser
{    公共虚拟的ICollection<&用户日志GT; UserLogs {搞定;组; }}公共类用户日志
{
    [键]
    公众的Guid UserLogID {搞定;组; }    公共字符串IPAD {搞定;组; }
    公众的DateTime LoginDate {搞定;组; }
    公共字符串userid {搞定;组; }    [ForeignKey的(用户ID)]
    公共虚拟ApplicationUser用户{搞定;组; }
}公共System.Data.Entity.DbSet<&用户日志GT;用户日志{搞定;组; }

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

Current Identity tables

 - Role
 - User
 - UserClaim
 - UserLogin
 - UserRole

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

New Table: UserLogs

Fields inside the new table:

  • UserLogID (PK)
  • UserID (FK)
  • IPAddress
  • LoginDate

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身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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