Expert Novice
Expert Novice

Reputation: 1963

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.

Upvotes: 13

Views: 26240

Answers (6)

user11457767
user11457767

Reputation: 1

Follow below steps :

  • open the folder location C:program file / microsoft visual studio 12/
  • search for developer Command prompt .
  • write the command : devenv /resetuserdata

Upvotes: 0

ChrisLively
ChrisLively

Reputation: 88044

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

Upvotes: 12

Marcel
Marcel

Reputation: 15722

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

Upvotes: 7

Yasser Shaikh
Yasser Shaikh

Reputation: 47774

Here is a simpler way to delete a user using SQL.

USE ASPNet
GO

DECLARE @UserId uniqueidentifier
SET @UserId = 'THE GUID 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

Upvotes: 12

CheGueVerra
CheGueVerra

Reputation: 7963

When creating a WebSite that is going to have a Membership manage users and roles, create an Admin/Support Web Page within your site that will be only visible available for Roles that can perform such operations as:

  • Delete User
  • Reset Password
  • Other Users management

It will come in handy when you have to support your End Users and the problems they are going to face.

Membership info from MSDN

Upvotes: 1

Kaf
Kaf

Reputation: 33809

On your project (Visual Studio) Top menu > Website > ASP.NET Configurations (Click on this)

It will open the configurations and then Security > Manage Users Do what you need there...

Upvotes: 2

Related Questions