如何在asp.net中删除用户帐户?

Exp*_*ice 11 c# asp.net forms-authentication c#-4.0

我有一个注册页面,我使用了以下演练:创建一个带有成员资格和用户登录的网站来制作我的网页.问题是注册页面创建了用户,但我对如何从存储它的数据库中删除用户帐户一无所知.

Not*_*tMe 11

成员资格提供程序具有DeleteUser方法.

http://msdn.microsoft.com/en-us/library/w6b0zxdw.aspx

以下也适用:

Membership.DeleteUser("username");


如果您想要基于SQL的解决方案:

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


Yas*_*ser 10

这是一种使用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
Run Code Online (Sandbox Code Playgroud)


Mar*_*cel 5

为了完整起见,这是一种类似于Yasser的解决方案,但是,按照OP的要求,使用UserName代替GUID:

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
Run Code Online (Sandbox Code Playgroud)

注意:Tim Gaunt从此博客中获取的基本SQL脚本