Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete user accounts in asp.net?

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.

like image 786
Expert Novice Avatar asked Mar 08 '12 15:03

Expert Novice


2 Answers

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

like image 113
NotMe Avatar answered Sep 26 '22 21:09

NotMe


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

like image 27
Marcel Avatar answered Sep 24 '22 21:09

Marcel