I'm using mvc5, and everything about user account management I do with UserManager. It works good with roles, claims, etc. But I didn't find how to delete user with UserManager. Is there a way to delete user with UserManager? I can create Database context with dbset and then delete it from this context, but I don't want create dbcontext, userclass, etc. for one delete method.
相关问题
- MVC5 EF6 Seed Method: Cannot insert NULL into colu
- How to generate URL for the action with attribute
- How to retrieve multiple columns from non-entity t
- Asp.Net MVC 5 Identity Create Database Admin Inter
- Unable to login to PiranhaCMS after setup
相关文章
- Why do I need a ToList() to avoid disposed context
- Cannot implicitly convert Web.Http.Results.JsonRes
- asp.net identity userName is unique?
- “Trust relationship between … and the primary doma
- MVC5 Identity/OWIN - Signout events
- ASP.Net Identity customizing UserProfile
- MVC. Net Error: Format of the initialization strin
- Visual Studio 2015. Failed to register URL for sit
I had issues with the above answer, though I was able to work out what's wrong. I kept getting a cascading error. Basically the user was being deleted without the role being deleted. DeleteAsync was not doing that for me (I have the latest build of Identity Framework). Ended up passing both the userid and role into my code, deleting the user from the role, then deleting the user. Seems to work fine.
Delete was not supported in UserManager in 1.0, but its supported in the upcoming 2.0 release, and in the current 2.0 nightly builds if you want to preview the changes early.
Using the updated asp.net identity I have the following code:
This one now deletes the user. It is also no need to delete from UserRoles table as that is taken care of by UserManager.DeleteAsync(user).
Hope this helps a few. I spent some time figuring out why I got some errors.
Trond