Deletes a user and any related user data from the database.
Namespace:
System.Web.Security
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Shared Function DeleteUser ( _
username As String _
) As Boolean
Dim username As String
Dim returnValue As Boolean
returnValue = Membership.DeleteUser(username)
public static bool DeleteUser(
string username
)
public:
static bool DeleteUser(
String^ username
)
public static function DeleteUser(
username : String
) : boolean
User data stored in the database for the Roles, Profile, or WebPart personalization is also deleted when you are using the SqlRoleProvider, SqlProfileProvider, and SqlPersonalizationProvider objects for data storage.
The following code example deletes the currently logged-on user and all related data.
<%@ 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(sender As Object, args As EventArgs)
Membership.DeleteUser(User.Identity.Name)
Response.Redirect("loginvb.aspx")
End Sub
Public Sub CancelButton_OnClick(sender As Object, args As EventArgs)
Response.Redirect("default.aspx")
End Sub
</script>
<html >
<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>
<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="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);
Response.Redirect("logincs.aspx");
}
public void CancelButton_OnClick(object sender, EventArgs args)
{
Response.Redirect("default.aspx");
}
</script>
<html >
<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>
<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>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources