Membership.DeleteUser Membership.DeleteUser Membership.DeleteUser Membership.DeleteUser Method

Definición

Elimina a un usuario de la base de datos.Deletes a user from the database.

Sobrecargas

DeleteUser(String) DeleteUser(String) DeleteUser(String) DeleteUser(String)

Elimina un usuario y cualquier dato del usuario relacionado de la base de datos.Deletes a user and any related user data from the database.

DeleteUser(String, Boolean) DeleteUser(String, Boolean) DeleteUser(String, Boolean) DeleteUser(String, Boolean)

Elimina a un usuario de la base de datos.Deletes a user from the database.

DeleteUser(String) DeleteUser(String) DeleteUser(String) DeleteUser(String)

Elimina un usuario y cualquier dato del usuario relacionado de la base de datos.Deletes a user and any related user data from the database.

public:
 static bool DeleteUser(System::String ^ username);
public static bool DeleteUser (string username);
static member DeleteUser : string -> bool
Public Shared Function DeleteUser (username As String) As Boolean

Parámetros

username
String String String String

Nombre del usuario que se va a eliminar.The name of the user to delete.

Devoluciones

Es true si se ha eliminado al usuario; en caso contrario, es false.true if the user was deleted; otherwise, false.

Excepciones

username es una cadena vacía o contiene una coma (,).username is an empty string or contains a comma (,).

Ejemplos

En el ejemplo de código siguiente se elimina el usuario que ha iniciado sesión actualmente y todos los datos relacionados.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"
    "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 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>

  <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(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 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>

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

Comentarios

Los datos de usuario almacenados en la base Rolesde Profiledatos para WebPart la personalización, o también se eliminan SqlRoleProvidercuando se usan SqlPersonalizationProvider los objetos, SqlProfileProvidery para el almacenamiento de datos.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.

Consulte también:

DeleteUser(String, Boolean) DeleteUser(String, Boolean) DeleteUser(String, Boolean) DeleteUser(String, Boolean)

Elimina a un usuario de la base de datos.Deletes a user from the database.

public:
 static bool DeleteUser(System::String ^ username, bool deleteAllRelatedData);
public static bool DeleteUser (string username, bool deleteAllRelatedData);
static member DeleteUser : string * bool -> bool
Public Shared Function DeleteUser (username As String, deleteAllRelatedData As Boolean) As Boolean

Parámetros

username
String String String String

Nombre del usuario que se va a eliminar.The name of the user to delete.

deleteAllRelatedData
Boolean Boolean Boolean Boolean

Es true para eliminar los datos relacionados con el usuario de la base de datos; es false para dejar los datos relacionados con el usuario en la base de datos.true to delete data related to the user from the database; false to leave data related to the user in the database.

Devoluciones

Es true si se ha eliminado al usuario; en caso contrario, es false.true if the user was deleted; otherwise, false.

Excepciones

username es una cadena vacía o contiene una coma (,).username is an empty string or contains a comma (,).

Ejemplos

En el ejemplo de código siguiente se elimina el usuario que ha iniciado sesión actualmente y todos los datos relacionados.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"
    "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>

Comentarios

Los usuarios eliminados de la base de datos solo se applicationNameeliminan del configurado.Users deleted from the database are only deleted from the configured applicationName.

Si deleteAllRelatedData es Profile SqlPersonalizationProvider WebPart Roles SqlProfileProvider SqlRoleProvider, los datos de usuario almacenados en la base de datos para la personalización, o también se eliminan cuando se usan los objetos, y para true almacenamiento de datos.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.

Consulte también:

Se aplica a