简体   繁体   中英

Asp.net core role based access identity / roles make user table self referencing

Hi I am trying to model an access control system where access is granted by role to certain actions. im trying to use asp.net core with identity and roles. it seems the default identity comes with its own tables for users. The users table i have need to be self referencing as a users will have managers who are also users.

is it possible to make the default table that comes with identity do that?

If you want to add additional properties to the already existing IdentityUser , all you have to do is inherit the IdentityUser class and then add your own properties then you go to the startup file and your dbcontext and do the following

public class InheritedUser : IdentityUser
{
   public bool HasTwoHeads { get; set;}

}

your startup

services.AddDefaultIdentity<InheritedUser>()
                .AddEntityFrameworkStores<CustomDbContext>()                               .AddDefaultTokenProviders()
.AddDefaultUI(Microsoft.AspNetCore.Identity.UI.UIFramework.Bootstrap4);

Then your Inherited DbContext

public class InheritedDbContext : IdentityDbContex<InheritedUser>
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM