Membership.DeleteUser Metoda

Definicja

Usuwa użytkownika z bazy danych.

Przeciążenia

DeleteUser(String)

Usuwa użytkownika i wszystkie powiązane dane użytkownika z bazy danych.

DeleteUser(String, Boolean)

Usuwa użytkownika z bazy danych.

DeleteUser(String)

Usuwa użytkownika i wszystkie powiązane dane użytkownika z bazy danych.

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

Parametry

username
String

Nazwa użytkownika do usunięcia.

Zwraca

Boolean

true jeśli użytkownik został usunięty; w przeciwnym razie , false.

Wyjątki

username jest pustym ciągiem lub zawiera przecinek (,).

username to null.

Przykłady

Poniższy przykład kodu usuwa aktualnie zalogowanego użytkownika i wszystkie powiązane dane.

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

Uwagi

Dane użytkownika przechowywane w bazie danych , RolesProfilelub WebPart personalizacji są również usuwane w przypadku używania SqlRoleProviderobiektów , SqlProfileProvideri SqlPersonalizationProvider do przechowywania danych.

Zobacz też

Dotyczy

DeleteUser(String, Boolean)

Usuwa użytkownika z bazy danych.

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

Parametry

username
String

Nazwa użytkownika do usunięcia.

deleteAllRelatedData
Boolean

true aby usunąć dane związane z użytkownikiem z bazy danych; false aby pozostawić dane powiązane z użytkownikiem w bazie danych.

Zwraca

Boolean

true jeśli użytkownik został usunięty; w przeciwnym razie , false.

Wyjątki

username jest pustym ciągiem lub zawiera przecinek (,).

username to null.

Przykłady

Poniższy przykład kodu usuwa aktualnie zalogowanego użytkownika i wszystkie powiązane dane.

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

Uwagi

Użytkownicy usunięci z bazy danych są usuwani tylko ze skonfigurowanego applicationNameelementu .

Jeśli deleteAllRelatedData jest to true, dane użytkownika przechowywane w bazie danych , RolesProfilelub WebPart personalizacji są również usuwane, gdy używasz SqlRoleProviderobiektów , SqlProfileProvideri SqlPersonalizationProvider do przechowywania danych.

Zobacz też

Dotyczy