SqlMembershipProvider.DeleteUser(String, Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 SQL Server 成员身份数据库中删除用户的成员身份信息。
public:
override bool DeleteUser(System::String ^ username, bool deleteAllRelatedData);
public override bool DeleteUser(string username, bool deleteAllRelatedData);
override this.DeleteUser : string * bool -> bool
Public Overrides Function DeleteUser (username As String, deleteAllRelatedData As Boolean) As Boolean
参数
- username
- String
要删除的用户的名称。
- deleteAllRelatedData
- Boolean
返回
true 如果用户已删除,则为否则,为 false. 如果用户在数据库中不存在,也会返回值 false 。
例外
username 为空字符串(“”),包含逗号或长度超过 256 个字符。
username 是 null。
示例
下面的代码示例删除当前登录的用户。
注释
此示例用于 SqlMembershipProvider 调用 SqlMembershipProvider 指定为 defaultProvider Web.config 文件中的指定项。 如果需要以类型 SqlMembershipProvider的形式访问默认提供程序,则可以强制转换 Provider 类的属性 Membership 。 若要以特定提供程序类型的形式访问其他配置的提供程序,可以使用其配置的名称访问它们,ProvidersMembership并将它们强制转换为特定的提供程序类型。
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void YesButton_OnClick(object sender, EventArgs args)
{
Membership.DeleteUser(User.Identity.Name, DeleteRelatedData.Checked);
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
public void CancelButton_OnClick(object sender, EventArgs args)
{
Response.Redirect("default.aspx");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Delete User</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Delete User</h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
<span style="color:red">Are you sure you want to delete the userid <b><%=User.Identity.Name%></b>?</span><br />
Delete related profile and roles data: <asp:CheckBox id="DeleteRelatedData"
checked="True" runat="Server" /><br />
<asp:Button id="YesButton" Text="Yes" OnClick="YesButton_OnClick" runat="server" />
<asp:Button id="CancelButton" Text="Cancel" OnClick="CancelButton_OnClick" runat="server" />
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Sub YesButton_OnClick(ByVal sender As Object, ByVal args As EventArgs)
Membership.DeleteUser(User.Identity.Name, DeleteRelatedData.Checked)
FormsAuthentication.SignOut()
FormsAuthentication.RedirectToLoginPage()
End Sub
Public Sub CancelButton_OnClick(ByVal sender As Object, ByVal args As EventArgs)
Response.Redirect("default.aspx")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Delete User</title>
</head>
<body>
<form id="form1" runat="server">
<h3>
Delete User</h3>
<asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
<p style="color:red">Are you sure you want to delete the userid <b><%=User.Identity.Name%></b>?</p>
<br />
Delete related profile and roles data:
<asp:CheckBox ID="DeleteRelatedData" Checked="True" runat="Server" /><br />
<asp:Button ID="YesButton" Text="Yes" OnClick="YesButton_OnClick" runat="server" />
<asp:Button ID="CancelButton" Text="Cancel" OnClick="CancelButton_OnClick" runat="server" />
</form>
</body>
</html>
注解
该类调用 Membership 此方法,从 ASP.NET 应用程序的配置文件中指定的 SQL Server 数据库中删除用户。
已删除的用户仅从配置的 ApplicationName中删除。
如果 deleteAllRelatedData 设置为 true,则也会删除数据库中存储的 Roles所有用户数据, Profile或 WebPart 为配置的 ApplicationName个性化功能删除。
如果数据库中不存在成员身份用户,并且deleteAllRelatedData是true,则为ProfileRoles属性中指定的ApplicationName应用程序删除相关数据和存储的用户信息或WebPart个性化设置功能。 因此, DeleteUser 即使对象不用于存储经过身份验证的用户信息, SqlMembershipProvider 该方法也可用于快速删除与用户相关的信息。
从参数值中剪裁 username 前导空格和尾随空格。