【问题标题】:Net Core Difference between IdentityRole and IdentityUserIdentityRole 和 IdentityUser 之间的网络核心区别
【发布时间】:2019-06-18 04:55:34
【问题描述】:

在Net Core Identity Management中,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)  
     { }  
 }  

【问题讨论】:

    标签: c# .net-core asp.net-core-mvc asp.net-identity


    【解决方案1】:

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

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

    用户有角色,角色有权限。喜欢创建应用程序

    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

    【讨论】:

      【解决方案2】:

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

      IdentityRole 是 ASP.NET Core MVC 类,其中包含有关应用程序中定义的 IdentityUsers 的用户角色(即使用域)的信息。

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

      【讨论】:

        猜你喜欢
        • 2020-10-08
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2012-10-31
        • 2016-05-03
        • 1970-01-01
        • 2011-10-03
        • 2018-09-04
        相关资源
        最近更新 更多