简体   繁体   中英

Recreating a deleted user in ASP.Net Membership

I'm using an ASP.Net Membership provider to handle user accounts on my website and I've set the DeleteUser() function to only delete data from the aspnet_Membership table as I'd like to keep the user ID and details in aspnet_Users for auditing.

I've encountered a problem whereby if I delete a user "bob", when someone creates a new user with the same username, then instead of creating a new aspnet_Users record with a new UserId (it's a GUID by default) it will instead link the new aspnet_Membership table record to the previously created "bob" account.

This means rather than creating a new user that happens to have the same username, it's re-activating the old user and linking their activity history together.

Is there a way to force ASP.Net membership to create a new aspnet_users record instead of hijacking the old one?

Thanks!

Unfortunately it seems that the ASP.Net Membership SQL Provider generates the User ID GUID using the username as a seed. This means that without deleting the user (which you wouldn't want to do if you were keeping an audit history) there is no clean way of creating another user with the same User ID.

To resolve my issue I have done the following:

  • Allowed ASP.Net Membership to assign a membership record to the asp_user record as it does by default
  • Added an audit record to my audit table explicitly specifying that a user has been re-created

This will allow me to check when writing audit queries whether the user performing an action was once removed, and hence whether they're likely to be the same person or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM