简体   繁体   English

Asp.net会员资格

[英]Asp.net membership

If I want to do an admin function like delete a user on the asp.net membership stuff that ships with the asp.net mvc sample. 如果我想做一个管理功能,比如在asp.net mvc样本附带的asp.net会员资料上删除用户。

I tried looking through the tables and realized that there was multiple tables that had rows added. 我试着查看表格并意识到有多个表添加了行。 I assume there must be a simpler way. 我认为必须有一个更简单的方法。

In your Membership provider there is a method: 在您的会员提供者中有一种方法:

public bool DeleteUser(string username, bool deleteAllRelatedData)

If this is the standard asp.net membership provider that method runs a stored proc that cleans the user from your DB. 如果这是标准的asp.net成员资格提供程序,则该方法运行存储过程,从数据库中清除用户。

Here is some more examples: http://www.4guysfromrolla.com/articles/091207-1.aspx 以下是一些例子: http//www.4guysfromrolla.com/articles/091207-1.aspx

Use the Membership API's . 使用Membership API

To delete a user, use the Membership.DeleteUse r method 要删除用户,请使用Membership.DeleteUse r方法

Membership.DeleteUser(User.Identity.Name, true);

不要直接从数据库中删除,通过成员资格提供程序并调用Membership.DeleteUser方法。

The Membership Provider base class has the methods you need. Membership Provider 基类具有您需要的方法。 For example to delete a user you use the DeleteUser method. 例如,要删除用户,请使用DeleteUser方法。 What you do NOT do is directly access the SQL database 你不做的是直接访问SQL数据库

You can also use the ASP.NET Configuration Tool. 您还可以使用ASP.NET配置工具。

http://msdn.microsoft.com/en-us/library/ms998347.aspx - Step 3 shows how to add users. http://msdn.microsoft.com/en-us/library/ms998347.aspx - 步骤3显示了如何添加用户。 The same principle applies for deleting them. 同样的原则适用于删除它们。 You can also mark them as inactive instead of deleting them. 您也可以将它们标记为非活动状态,而不是删除它们。 I usually mark them as inactive to preserve my database relationships. 我通常将它们标记为不活动以保留我的数据库关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM