user11612831
user11612831

Reputation:

Net Core Difference between IdentityRole and IdentityUser

In Net Core Identity Management, what is the difference between IdentityRole and 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)  
     { }  
 }  

Upvotes: 1

Views: 5032

Answers (2)

cdev
cdev

Reputation: 5361

Identity user: Use for authenticate ex : login user

Identity role : Use for authorization ex: Administrator (above user belongs to administrator role)

Users have roles, roles have permissions. Like create app

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

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

Upvotes: 1

M. Arnold
M. Arnold

Reputation: 425

IdentityUser is the ASP.NET Core MVC class that contains information about users registered in your application. It contains default properties such as username, email, password e.t.c. This class can be inherited and more properties provided.

IdentityRole is the ASP.NET Core MVC class that contains information about user roles (which are usage domains) of the IdentityUsers defined in your application.

An IdentityUser can contain many IdentityRoles and an IdentityRole can contain many IdentityUsers. Hence in your application, IdentityRoles can be used as filters for authentication where only IdentityUsers that belong to a certain IdentityRole/s can access either the class or method.

Upvotes: 0

Related Questions