是否可以从默认表AspNetUsers中删除行?如果是,请解释

本文关键字:如果 解释 删除行 默认 AspNetUsers 是否 | 更新日期: 2023-09-27 18:16:42

是否可以从默认表AspNetUsers中删除行?如果是,请解释

i能够删除具有Fk的AspNetUsers的记录。

public ActionResult Delete(STUDENT st)
{
Var studentuser = st.user;
St.user = null;
db.Entry (st)。状态= EntityState.Deleted;db. savechanges();//删除数据库成功
var userid = User.Identity.GetUserId();
var user = _userManager.FindById(userid);

_userManager.DeleteAsync(用户);return RedirectToAction("Index", "Admin");
}

是否可以从默认表AspNetUsers中删除行?如果是,请解释

这是我之前用来删除用户的代码片段

// Find the user
var user = await _userManager.FindByIdAsync(id);
var logins = user.Logins;
// Delete every login, if he has
foreach (var login in logins.ToList())
{
  await _userManager.RemoveLoginAsync(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
}
// Delete every role, if he has
var rolesForUser = await _userManager.GetRolesAsync(id);
if (rolesForUser.Count() > 0)
{
    foreach (var item in rolesForUser.ToList())
    {
       // item should be the name of the role
       var result = await _userManager.RemoveFromRoleAsync(user.Id, item);
    }
}
// Delete the user itself
_await _userManager.DeleteAsync(user);

是的。但首先,在删除该用户之前,您必须删除该用户的所有现有角色。

示例:Roles.RemoveUserFromRoles("userName",Roles.GetRolesForUser("userName"));

有一个类似问题的链接:how-to-delete-a- simplembershipuser