2017-02-09 43 views
1

我有這段代碼來定義我的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; 
    } 
} 

回答

1

您可以通過派生自IdentityRole類將自定義字段添加到Roles表。

代碼片段:

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

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