Why's Delete not supported in ASP.Net Identity

2019-01-27 15:55发布

问题:

I was tinkering with the new auth features that recently RTM'd with Visual Studio 2013.

While implementing a custom UserStore, I was having a look at the decompiled sources for the UserStore that ships in the box, Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>. I noticed that the method for deleting a user was not supported:

  public class UserStore<TUser> : IUserLoginStore<TUser>, IUserClaimStore<TUser>, IUserRoleStore<TUser>, IUserPasswordStore<TUser>, IUserSecurityStampStore<TUser>, IUserStore<TUser>, IDisposable where TUser : IdentityUser
  {
       // other stuff omitted

    public virtual Task DeleteAsync(TUser user)
    {
      throw new NotSupportedException();
    }
  }

That's strange isn't it? Why is deleting a user not supported?

I admit I can't remember a production system that I've written that hard deleted user records, but I don't understand why this functionality is not supported.

Is there a technical reason or is it simply because Microsoft feels that deleting user records is "bad" and leaves it as an exercise for the developer to override the method?

Update

In an attempt to understand what the ASP.NET team was thinking, I searched for framework usages of DeleteAsync(TUser user). Nothing in the framework seems to invoke it. So, it seems that they could have completely left the member off of the IUserStore<TUser> interface.

My conclusion at this point is that it's there to implement if you want and how you want and that it will only ever be invoked by your application code or future user management libraries.

回答1:

We just ran out of time to complete it for 1.0, it will be added in Update 1 as part of the rest of the admin related apis like an IQueryable Users property on UserManager. (It's already implemented in nightly 1.1-alpha1 packages)



回答2:

Delete User account

In 1.0, if you had to delete a User, you could not do it through the UserManager. They have now fixed it with 2.0:

var result = await UserManager.DeleteAsync(user);

See http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx