Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NET标识中添加自定义表?_C#_Asp.net_Webforms_Asp.net Identity - Fatal编程技术网

C# 如何在ASP.NET标识中添加自定义表?

C# 如何在ASP.NET标识中添加自定义表?,c#,asp.net,webforms,asp.net-identity,C#,Asp.net,Webforms,Asp.net Identity,我正在web表单应用程序上使用ASP.NET标识。 以下是我目前的身份表: 当前标识表 我需要添加一个新表来存储附加信息 新表:UserLogs 新表中的字段: UserLogID(PK) 用户ID(FK) IP地址 罗吉恩代特 如何添加此自定义表?我知道如何在现有表中添加自定义字段,但我不知道如何实现这一点 我感谢您为我的问题找到解决方案所做的努力。首先,我建议您了解一下代码优先实体框架,因为这就是在您首次创建新MVC5应用程序时创建用户表的方式 如果希望使用通过EntityFramewo

我正在web表单应用程序上使用ASP.NET标识。 以下是我目前的身份表:

当前标识表 我需要添加一个新表来存储附加信息

新表:UserLogs 新表中的字段:

  • UserLogID(PK)
  • 用户ID(FK)
  • IP地址
  • 罗吉恩代特
如何添加此自定义表?我知道如何在现有表中添加自定义字段,但我不知道如何实现这一点


我感谢您为我的问题找到解决方案所做的努力。

首先,我建议您了解一下代码优先实体框架,因为这就是在您首次创建新MVC5应用程序时创建用户表的方式

如果希望使用通过EntityFramework创建的代码优先数据库,可以找到它的实现方式

在您了解了一些关于它的核心内容之后,您可以直接转到“模型”文件夹中的项目,直接转到>AccountModel.cs

这里有一个扩展DbContext的类,其中包含一个构造函数,该构造函数允许访问将要在其上使用数据库的connectionstring

如果你太懒于首先阅读代码,请简短介绍重要内容:

DbSet意味着DbSet中的模型将被创建到一个表中。类中的变量是即将创建的列。但是如果你想要外键之类的东西,你肯定得先读代码

祝你好运

公共类应用程序用户:IdentityUser
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; }
{ 公共虚拟ICollection用户日志{get;set;} } 公共类用户日志 { [关键] 公共Guid UserLogID{get;set;} 公共字符串IPAD{get;set;} 公共日期时间登录数据{get;set;} 公共字符串用户标识{get;set;} [外键(“用户ID”)] 公共虚拟应用程序用户{get;set;} } public System.Data.Entity.DbSet UserLog{get;set;}
可能重复的问题请检查答案,我想这就足够了。让我检查一下,然后我会让您知道。Thanks@mybirthname我有一个问题。公共虚拟应用程序用户{get;set;},在这里我应该添加我的列,它存在于我的日志表中,对吗?感谢这篇有用的文章,但我没有使用MVC,它是(Web表单)。先生,据我所知,在Webforms中也使用了与EntityFramework相同的结构。我建议你确认一下,这几乎是一样的。如果没有,那么我很抱歉,我希望你很快找到你想要的。我同意你的看法,但我的项目中没有AccountModel.cs。在模型下,我有IdentityModels.cs。这是因为您使用的是Identity 2.0@KevinMaxwell@scheien我假设Identity 2.0是最新的?正确吗?我已执行Identity 2.0脚本将表添加到自定义数据库中。然后,我使用DB-first方法添加了模型。现在,我正在尝试添加列,正如您所做的那样。我首先将列添加到ASPNetUser表,然后将属性添加到applicationuser,然后更新模型。但是,它会生成一个错误。你能告诉我步骤和顺序吗?
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; }