Membership.DeleteUser Method (String, Boolean)

Deletes a user from the database.

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

public static bool DeleteUser (
	string username,
	bool deleteAllRelatedData
public static boolean DeleteUser (
	String username, 
	boolean deleteAllRelatedData
public static function DeleteUser (
	username : String, 
	deleteAllRelatedData : boolean
) : boolean
Not applicable.



The name of the user to delete.


true to delete data related to the user from the database; false to leave data related to the user in the database.

Return Value

true if the user was deleted; otherwise, false.

Exception typeCondition


username is an empty string or contains a comma (,).


username is a null reference (Nothing in Visual Basic).

Users deleted from the database are only deleted from the configured applicationName.

If deleteAllRelatedData is true, 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="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

public void YesButton_OnClick(object sender, EventArgs args)
  Membership.DeleteUser(User.Identity.Name, DeleteRelatedData.Checked);


public void CancelButton_OnClick(object sender, EventArgs args)

<html xmlns="" >
<title>Sample: Delete User</title>

<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" />


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions