IdentityRole 和 IdentityUser 之间的 Net Core 区别

Net Core Difference between IdentityRole and IdentityUser

在 Net Core 身份管理中,IdentityRole 和 IdentityUser 有什么区别?

public class AppIdentityRole : IdentityRole  
 { }  

 public class AppIdentityUser : IdentityUser  
 {  
     public int Age { get; set; }  
 }  


 public class AppIdentityDbContext   
   : IdentityDbContext<AppIdentityUser, AppIdentityRole, string>  
 {  
     public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options)  
         : base(options)  
     { }  
 }  

身份用户:用于身份验证 例如:登录用户

身份角色:用于授权 ex:管理员(以上用户属于管理员角色)

用户有角色,角色有权限。点赞创建应用

https://social.technet.microsoft.com/wiki/contents/articles/51333.asp-net-core-2-0-getting-started-with-identity-and-role-management.aspx

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.2&tabs=visual-studio

IdentityUser 是 ASP.NET 核心 MVC class,其中包含有关在您的应用程序中注册的用户的信息。它包含默认属性,例如用户名、电子邮件、密码 e.t.c。这个class可以继承,提供更多的属性。

IdentityRole 是 ASP.NET 核心 MVC class,它包含有关应用程序中定义的 IdentityUser 的用户角色(即使用域)的信息。

一个 IdentityUser 可以包含多个 IdentityRoles,一个 IdentityRole 可以包含多个 IdentityUser。因此,在您的应用程序中,IdentityRoles 可用作身份验证过滤器,其中只有属于某个 IdentityRole/s 的 IdentityUsers 才能访问 class 或方法。