I have a Register page, I used the following Walkthrough: Creating a Web Site with Membership and User Login to make my webpage. The problem is the Registration page creates users, but I am clueless about how to delete user accounts from the Database where it gets stored.
The membership provider has a DeleteUser method.
http://msdn.microsoft.com/en-us/library/w6b0zxdw.aspx
The following works just as well:
Membership.DeleteUser("username");
If you want a SQL based solution:
http://web.archive.org/web/20130407080036/http://blogs.rawsoft.nl/remco/post/2009/02/05/How-to-Remove-users-from-the-ASPNet-membership-database.aspx
For the completeness' sake, here is a solution similar to Yasser's, however, with using the UserName instead of the GUID as the OP has asked:
DECLARE @UserId uniqueidentifier
SET @UserId = (SELECT TOP(1) UserID FROM aspnet_Users
WHERE UserName = 'THE USERNAME OF THE USER HERE')
DELETE FROM aspnet_Profile WHERE UserID = @UserId
DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserId
DELETE FROM aspnet_PersonalizationPerUser WHERE UserID = @UserId
DELETE FROM dbo.aspnet_Membership WHERE UserID = @UserId
DELETE FROM aspnet_users WHERE UserID = @UserId
Note: Base SQL script taken from this blog by Tim Gaunt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With