Delete user and reassign to Anonymous

Delete user and reassign to Anonymous

This question has suggested answer(s)

Hello,

    Is there a way to programmatically delete a user account and have that user content assigned to "Anonymous" like the admin screen does it. We have tried the code below but that fails if the user is not an administrator. Any way to get around that? How is the reassignment done programmatically?

           UsersDeleteOptions deleteOptions = new UsersDeleteOptions { Id = userId };

           PublicApi.Users.Delete(deleteOptions);

Thanks,

Jean

All Replies
  • Whenever a user is deleted via the public APIs, either in-process as you've shown in your example of or via REST, the deleted user's content will automatically be assigned to the Anonymous user.

    The user in context (logged in user) when running your code above doesn't necessarily have to be an administrator but they must have Manage Membership permission to perform the successfully.

  • Dan,

         Thank you much. My next question is I don't want every user to be created with the "Manage Membership" permission but our requirements are that every user should be able to delete their account. Should we create a "shadow" user with just the "Manage Membership" permission and somehow right before doing the delete call switch the user context from the current user to the "shadow" user? Can this be done using the in-process API? How do we switch the context back to the current user?