首页 > 其他 > 详细

Identity角色管理一(准备工作)

时间:2020-06-30 11:30:52      阅读:67      评论:0      收藏:0      [点我收藏+]

因角色管理需要有用户才能进行(需要将用户从角色中添加,删除)故角色管理代码依托用户管理

只需在Startup服务中添加角色管理即可完成

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();

    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("Default")));

    //增加用户及用户组服务
    services.AddIdentity<IdentityUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
        .AddEntityFrameworkStores<ApplicationDbContext>();
}

因为需要角色管理,用户管理,所以需要注入构造方法中方便使用

private readonly RoleManager<IdentityRole> _roleManager;
private readonly UserManager<IdentityUser> _userManager;

public RoleController(RoleManager<IdentityRole> roleManager, UserManager<IdentityUser> userManager)
{
    _roleManager = roleManager;
    _userManager = userManager;
}

 

Identity角色管理一(准备工作)

原文:https://www.cnblogs.com/liessay/p/13211878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!