向MVC SimpleMembership角色添加自定义字段

问题描述:

我有这段代码来定义我的ApplicaitonUser。名称和创建是我添加的自定义字段。向MVC SimpleMembership角色添加自定义字段

如何为角色做同样的事情?我需要为它们添加一个整数字段。

public class ApplicationUser : IdentityUser 
{ 
    public DateTime Created { get; set; } 
    public string Name { get; set; } 

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) 
    { 
     // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
     var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
     // Add custom user claims here 
     return userIdentity; 
    } 

    public ApplicationUser() 
    { 
     Created = DateTime.UtcNow; 
    } 
} 

您可以通过派生自IdentityRole类将自定义字段添加到Roles表。

代码片段:

public class ApplicationRole : IdentityRole 
    { 
     public ApplicationRole() : base() 
     { 
     } 

     // New property 
     public int MasterRoleId{ get; set; } 
    }