Membership.DeleteUser メソッド

定義

データベースからユーザーを削除します。

オーバーロード

名前 説明
DeleteUser(String)

ユーザーと関連するユーザー データをデータベースから削除します。

DeleteUser(String, Boolean)

データベースからユーザーを削除します。

DeleteUser(String)

ユーザーと関連するユーザー データをデータベースから削除します。

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

パラメーター

username
String

削除するユーザーの名前。

返品

true ユーザーが削除された場合。それ以外の場合は false

例外

username は空の文字列であるか、コンマ (,) を含みます。

usernamenullです。

次のコード例では、現在ログオンしているユーザーとすべての関連データを削除します。

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

注釈

RolesProfile、またはWebPartパーソナル化のためにデータベースに格納されているユーザー データは、データ ストレージにSqlRoleProviderSqlProfileProvider、およびSqlPersonalizationProviderオブジェクトを使用している場合にも削除されます。

こちらもご覧ください

適用対象

DeleteUser(String, Boolean)

データベースからユーザーを削除します。

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

パラメーター

username
String

削除するユーザーの名前。

deleteAllRelatedData
Boolean

true データベースからユーザーに関連するデータを削除する場合。データベース内のユーザーに関連するデータを残す false

返品

true ユーザーが削除された場合。それ以外の場合は false

例外

username は空の文字列であるか、コンマ (,) を含みます。

usernamenullです。

次のコード例では、現在ログオンしているユーザーとすべての関連データを削除します。

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

注釈

データベースから削除されたユーザーは、構成された applicationNameからのみ削除されます。

deleteAllRelatedDatatrueされている場合、データ ストレージにRolesProfileWebPartオブジェクトを使用している場合は、SqlRoleProviderSqlProfileProvider、またはSqlPersonalizationProviderパーソナル化のためにデータベースに格納されているユーザー データも削除されます。

こちらもご覧ください

適用対象