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


C# UserManager.RemoveFromRoles方法代码示例

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


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

示例1: UpdateUser

 internal bool UpdateUser(string username, string realUsername, string permission)
 {
     IdentityResult result = null;
     Models.ApplicationDbContext context = new Models.ApplicationDbContext();
     var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     var user = userMgr.FindByName(username);
     if (!string.IsNullOrEmpty(realUsername))
     {
         user.RealUserName = realUsername;
         result = userMgr.Update(user);
     }
     if (!string.IsNullOrEmpty(permission) && !userMgr.IsInRole(user.Id, permission))
     {
         userMgr.RemoveFromRoles(user.Id, "read", "edit", "administrator");
         switch (permission)
         {
             case "administrator":
                 result = userMgr.AddToRole(user.Id, "administrator");
                 break;
             case "edit":
                 result = userMgr.AddToRole(user.Id, "edit");
                 break;
             default:
                 result = userMgr.AddToRole(user.Id, "read");
                 break;
         }
     }
     if (result == IdentityResult.Success) return true; else return false;
 }
开发者ID:OurFirstOrgan,项目名称:FlyingSnow.Travel,代码行数:29,代码来源:RoleActions.cs

示例2: AssignRole

 public async Task<ActionResult> AssignRole(string username, string rolename)
 {
     UserStore<ApplicationUser> userStore = new UserStore<ApplicationUser>(_identityDb);
     UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(userStore);
     var user = userManager.Users.FirstOrDefault(u => u.UserName == username);
     await Task.Run(() => userManager.RemoveFromRoles(user.Id, userManager.GetRoles(user.Id).ToArray()));
     //var role = roles.FirstOrDefault(r => r == rolename);
     //if(role == null)
     userManager.AddToRole(user.Id, rolename);
     return RedirectToAction("Users", "Admin");
 }
开发者ID:weweboom,项目名称:SE1-Sprint1-Group3,代码行数:11,代码来源:AdminController.cs

示例3: grvUsers_RowUpdating

        protected void grvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = grvUsers.Rows[e.RowIndex];
            var id = grvUsers.DataKeys[e.RowIndex].Value.ToString();

            var firstName = ((TextBox)row.FindControl("txtFirstName")).Text;
            var lastName = ((TextBox)row.FindControl("txtLastName")).Text;
            var email = ((TextBox)row.FindControl("txtEmail")).Text;
            var currentPassword = ((TextBox)row.FindControl("txtCurrentPassword")).Text;
            var newPassword = ((TextBox)row.FindControl("txtNewPassword")).Text;
            var role = ((DropDownList)row.FindControl("ddlRoleEdit")).Text;
            var jobClinic = ((DropDownList)row.FindControl("ddlJobClinicEdit")).Text; //TODO: Automatically edit RelationType (exept Writer) on files.
            var isActive = ((CheckBox)row.FindControl("chkIsActive")).Checked;

            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);
            var user = userManager.FindById(id);

            if (user != null && (
                userManager.FindById(SharedClass.CurrentUser).UserName == "Admin" ||
                user.UserName != "Admin"
                ))
            {
                if (newPassword != "")
                {
                    var result = userManager.ChangePassword(id, currentPassword, newPassword);
                }
                userManager.SetEmail(id, email);
                userManager.RemoveFromRoles(id, userManager.GetRoles(id).ToArray());
                userManager.AddToRole(id, role);

                using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
                {
                    BSI__Clinic_Employee employee = mc.BSI__Clinic_Employees.Where(o => o.Id == id).First();
                    employee.First_Name = firstName;
                    employee.Last_Name = lastName;
                    employee.Job_Clinic = jobClinic;
                    employee.Is_Active = isActive;

                    mc.SaveChanges();
                }
            }
            grvUsers.EditIndex = -1;
        }
开发者ID:manili,项目名称:Medical_Clinic,代码行数:44,代码来源:User_Management.aspx.cs

示例4: Edit

        public ActionResult Edit([Bind(Include = "FirstName,LastName,Email,PhoneNumber,UserName")] ApplicationUser applicationUser)
        {
            if (ModelState.IsValid)
            {
                var userStore = new UserStore<ApplicationUser>(db);
                var userManager = new UserManager<ApplicationUser>(userStore);

                string userId = userManager.FindByName(applicationUser.UserName).Id;

                userManager.RemoveFromRoles(userId, userManager.GetRoles(userId).ToArray());
                userManager.AddToRoles(userId, Request["Role"].Split(','));

                userManager.Update(applicationUser);

                return RedirectToAction("Index");
            }
            return View(applicationUser);
        }
开发者ID:ChrisSallee,项目名称:Kanban,代码行数:18,代码来源:ApplicationUsersController.cs

示例5: ChangeUserAdminStatus

        private JsonResult ChangeUserAdminStatus(string userId, bool admin)
        {
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_db));
            ApplicationUser user = userManager.FindById(userId);
            IdentityResult result = null;
            
            if (admin)
                result = userManager.AddToRole(userId, "Admin");
            else
                result = userManager.RemoveFromRoles(userId, "Admin");

            string errors = "";

            foreach (string er in result.Errors)
            {
                errors += er + " ";
            }

            if (result.Succeeded)
                return Json(new AppMessage() { Type = AppMessage.Success, Message = String.Format(AppString.UserIsNow, user.Email, admin ? AppString.PartialIsNowAdmin : AppString.PartialIsNoLongerAdmin) });
            else
                return Json(new AppMessage() { Type = AppMessage.Error, Message = String.Format(AppString.UpdateForTypeFailed, AppString.User)  + " " + errors  });
        }
开发者ID:jonatancamacho,项目名称:ASP.NET--Sogeti,代码行数:23,代码来源:AdminController.cs


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