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

时间:2012-03-08 15:33:54

标签: c# asp.net c#-4.0 forms-authentication

我有一个注册页面,我使用以下Walkthrough: Creating a Web Site with Membership and User Login来创建我的网页。问题是注册页面创建了用户,但我对如何从存储它的数据库中删除用户帐户一无所知。

6 个答案:

答案 0 :(得分:10)

成员资格提供程序具有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

答案 1 :(得分:9)

这是一种使用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

答案 2 :(得分:4)

为了完整性'但是,这是一个类似于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

注意:基本SQL脚本取自this blog by Tim Gaunt

答案 3 :(得分:2)

在您的项目(Visual Studio)顶部菜单>网站> ASP.NET配置(单击此处)

它将打开配置然后安全>管理用户 做你需要的......

答案 4 :(得分:1)

创建将要有会员管理用户和角色的WebSite时,在您的站点内创建一个管理员/支持网页,该网页仅对可以执行以下操作的角色可见:

  • 删除用户
  • 重置密码
  • 其他用户管理

当您必须支持最终用户及其将要面对的问题时,它会派上用场。

Membership info from MSDN

答案 5 :(得分:0)

请按照以下步骤操作:

  • 打开文件夹位置C:program file / microsoft visual studio 12/
  • 搜索开发者Command prompt
  • 编写命令:devenv / resetuserdata