本文整理汇总了C#中ApplicationUserManager.RemoveFromRoleAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUserManager.RemoveFromRoleAsync方法的具体用法?C# ApplicationUserManager.RemoveFromRoleAsync怎么用?C# ApplicationUserManager.RemoveFromRoleAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationUserManager
的用法示例。
在下文中一共展示了ApplicationUserManager.RemoveFromRoleAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteUser
public async Task<ActionResult> DeleteUser(string Username)
{
try
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context));
ApplicationUser user = context.Users.Where(u => u.UserName.Equals(Username, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
string userID = user.Id;
if (ModelState.IsValid)
{
if (userID == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var userDel = await manager.FindByIdAsync(userID);
var logins = user.Logins;
foreach (var login in logins.ToList())
{
await manager.RemoveLoginAsync(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
}
var rolesForUser = await manager.GetRolesAsync(userID);
if (rolesForUser.Count() > 0)
{
foreach (var item in rolesForUser.ToList())
{
// item should be the name of the role
var result = await manager.RemoveFromRoleAsync(user.Id, item);
}
}
await manager.DeleteAsync(user);
TempData["ValidationMessage"] = ("Success: " + " " + Username + " " + "Was Removed");
return View("ManageUser");
}
else
{
TempData["ValidationMessage"] = ("Error: " + " " + Username + " " + "Was Not Removed");
return View("ManageUser");
}
}
catch
{
TempData["ValidationMessage"] = ("Error: Something Went Wrong");
return View("ManageUser");
}
}