当前位置: 首页>>代码示例>>C#>>正文


C# ApplicationRoleManager.Create方法代码示例

本文整理汇总了C#中ApplicationRoleManager.Create方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationRoleManager.Create方法的具体用法?C# ApplicationRoleManager.Create怎么用?C# ApplicationRoleManager.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApplicationRoleManager的用法示例。


在下文中一共展示了ApplicationRoleManager.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRole

 public bool CreateRole(string name)
 {
     var rm = new ApplicationRoleManager(
         new RoleStore<IdentityRole>(context));
     var idResult = rm.Create(new IdentityRole(name));
     return idResult.Succeeded;
 }
开发者ID:BenVandenberk,项目名称:EindwerkNET,代码行数:7,代码来源:IdentityModels.cs

示例2: CreateNewRole

 public void CreateNewRole(Role model)
 {
     ApplicationRoleManager rm = new ApplicationRoleManager(new ApplicationRoleStore(new ApplicationDbContext()));
     rm.Create(new ApplicationRole(model.Name)
     {
         Id = Guid.NewGuid().ToString()
     });
 }
开发者ID:hurtonypeter,项目名称:onlab,代码行数:8,代码来源:PerseusRepository.cs

示例3: SeedIdentityForEF

        public static void SeedIdentityForEF(ApplicationDbContext context)
        {
            if ((!context.Roles.Any()) && (!context.Users.Any()))
            {
                var roleStore = new ApplicationRoleStore(context);
                //var roleManager = new RoleManager<ApplicationRole, int>(roleStore);

                var roleManager = new ApplicationRoleManager(roleStore);

                var role = new ApplicationRole
                {
                    Name = "Admin",
                    Description = "Super Admin User group"
                };
                roleManager.Create(role);

                var userStore = new UserStore<ApplicationUser,
                                                ApplicationRole,
                                                int,
                                                ApplicationUserLogin,
                                                ApplicationUserRole,
                                                ApplicationUserClaim>(context);
                var userManager = new ApplicationUserManager(userStore);

                var user = new ApplicationUser
                {
                    Email = "[email protected]",
                    UserName = "SuperUser",
                    EmailConfirmed = true
                };

                user.FirstName = "Jack";
                user.LastName = "Smith";

                userManager.Create(user, "[email protected]");
                var result = userManager.SetLockoutEnabled(user.Id, false);

                userManager.AddToRole(user.Id, "Admin");

                //added group manager
                var groupManager = new ApplicationGroupManager(roleManager,userManager);
                var newGroup = new ApplicationGroup("SuperAdmins", "Full Access to All");

                groupManager.CreateGroup(newGroup);
                groupManager.SetUserGroups(user.Id, new int[] { newGroup.Id });
                groupManager.SetGroupRoles(newGroup.Id, new string[] { role.Name });
            }
        }
开发者ID:kdcllc,项目名称:KDCLLCWeb,代码行数:48,代码来源:IdentityInitialize.cs


注:本文中的ApplicationRoleManager.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。