如前所述,在1.0中,如果必须删除用户,则无法通过UserManager进行删除,并且在2.0版中已修复,因此我们可以执行以下操作来删除用户:
var user = await UserManager.FindByIdAsync(id);
if (user == null)
{
return HttpNotFound();
}
var result = await UserManager.DeleteAsync(user);
但它不起作用。这个问题有什么解决办法吗?
var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
if (um.IsInRole(formCollection["user"], role))
{
um.RemoveFromRole(formCollection["user"], role);
}
using RemoveFromRole function and pass (userid ,rolename);