繁体   English   中英

如何在Asp.Net MVC 4 Simple Membership的用户配置文件中添加FistName和LastName的其他字段?

[英]How to Add Extra Fields of FistName and LastName in Userprofile of Asp.Net MVC 4 Simple Membership?

我想在UserProfile Asp.Net简单成员身份中添加2个额外字段,但无法添加,也无法从Internet找到任何帮助。 请给我一些解决方案。

提前致谢

要将字段添加到SimpleMembership中的UserProfile中(我假设您要使用迁移和EF):

  1. 确保已启用迁移(使用程序包管理器控制台中的Enable-Migration
  2. 编辑UserProfile类(假设您使用的是Visual Studio 2012->新建项目-> ASP.NET MVC 4 Web应用程序-> Internet应用程序模板,将为您创建此模板)以添加新属性(示例下面)
  3. 添加一个迁移,该迁移将使用Add-Migration命令更新您的数据库。
  4. (可选)编辑生成的迁移以处理默认值和不可为空的字段。
  5. 使用Update-Database命令对您的开发数据库运行该迁移。

我已经在此答案中使用UserProfile提供了有关SimpleMembership如何工作的概述。 请注意,可以将UserProfile与所有其他类一起从UsersContext移动到相同的DbContext,而不必在单独的上下文中。

SimpleMembership旨在与代码优先EF开发一起很好地使用,所以这就是我上面概述的过程。 一个例子更新UserProfile类与ForenameSurnameLoginCount场会是什么样子:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    public string UserName { get; set; }

    [MaxLength(40)]
    [Required]
    public string Forename { get; set; }

    [MaxLength(40)]
    [Required]
    public string Surname { get; set; }

    [Required]
    public int LoginCount { get; set; }
}

参考文献:

  1. ASP.NET MVC 4实体框架脚手架和迁移 -任务3显示了如何启用迁移
  2. MSDN:代码优先迁移 -您需要了解的有关迁移的所有信息
  3. StackOverflow:如何将自己的数据库与SimpleMembership和WebSecurity一起使用? 什么是MVC4安全性?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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