C# 如何删除asp.net中的用户帐户?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9620261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:12:36  来源:igfitidea点击:

How to delete user accounts in asp.net?

c#asp.netc#-4.0forms-authentication

提问by Expert Novice

I have a Register page, I used the following Walkthrough: Creating a Web Site with Membership and User Loginto 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.

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

采纳答案by NotMe

The membership provider has a DeleteUser method.

成员资格提供程序有一个 DeleteUser 方法。

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

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

The following works just as well:

以下也同样有效:

Membership.DeleteUser("username");

Membership.DeleteUser("username");



If you want a SQL based solution:

如果您想要基于 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

http://web.archive.org/web/20130407080036/http://blogs.rawsoft.nl/remco/post/2009/02/05/How-to-Remove-users-from-the-ASPNet-membership-数据库.aspx

回答by Kaf

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

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

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

它将打开配置,然后安全 > 管理用户在那里执行您需要的操作...

回答by CheGueVerra

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

来自 MSDN 的会员信息

回答by Yasser Shaikh

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

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

回答by Marcel

For the completeness' sake, here is a solution similar to Yasser's, however, with using the UserNameinstead of the GUID as the OP has asked:

为了完整起见,这里有一个类似于 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

Note: Base SQL script taken from this blog by Tim Gaunt

注意:基本 SQL 脚本取自Tim Gaunt 的博客

回答by user11457767

Follow below steps :

请按照以下步骤操作:

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

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