Roles.DeleteRole 메서드

정의

데이터 원본에서 역할을 제거합니다.

오버로드

Name Description
DeleteRole(String, Boolean)

데이터 원본에서 역할을 제거합니다.

DeleteRole(String)

데이터 원본에서 역할을 제거합니다.

DeleteRole(String, Boolean)

데이터 원본에서 역할을 제거합니다.

public:
 static bool DeleteRole(System::String ^ roleName, bool throwOnPopulatedRole);
public static bool DeleteRole(string roleName, bool throwOnPopulatedRole);
static member DeleteRole : string * bool -> bool
Public Shared Function DeleteRole (roleName As String, throwOnPopulatedRole As Boolean) As Boolean

매개 변수

roleName
String

삭제할 역할의 이름입니다.

throwOnPopulatedRole
Boolean

이면 true하나 이상의 멤버가 있는 경우 roleName 예외를 throw합니다.

반품

데이터 원본에서 삭제되었으면 />이고, 그렇지 않으면 .입니다.

예외

roleNamenull입니다.

roleName 은 빈 문자열입니다.

roleName에는 하나 이상의 멤버가 throwOnPopulatedRole있으며 true

-또는-

역할 관리를 사용할 수 없습니다.

예제

다음 코드 예제에서는 데이터 원본에서 역할을 삭제합니다. 역할 관리를 사용하도록 설정하는 Web.config 파일의 예는 다음을 참조하세요 Roles.


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

  string[] rolesArray;

  public void Page_Load(object sender, EventArgs args)
  {
    if (!IsPostBack)
    {
      // Bind roles to ListBox.

      rolesArray = Roles.GetAllRoles();
      RolesListBox.DataSource = rolesArray;
      RolesListBox.DataBind();
    }
  }


  public void DeleteRole_OnClick(object sender, EventArgs args)
  {
    string delRole = "";

    try
    {
      delRole = RolesListBox.SelectedItem.Value;

      Roles.DeleteRole(delRole);

      Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' deleted.";


      // Re-bind roles to ListBox.

      rolesArray = Roles.GetAllRoles();
      RolesListBox.DataSource = rolesArray;
      RolesListBox.DataBind();
    }
    catch
    {
      Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' <u>not</u> deleted.";
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Sample: Delete Role</title>
</head>
<body>
  <form runat="server" id="PageForm">
    <h3>
      Delete Role</h3>
    <asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
    <table border="0">
      <tr>
        <td valign="top">
          Delete Role:</td>
        <td valign="top">
          <asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
        <td valign="top">
          <asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
      </tr>
    </table>
  </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">

  Dim rolesArray() As String

  Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)

    If Not IsPostBack Then
      ' Bind roles to ListBox.

      rolesArray = Roles.GetAllRoles()
      RolesListBox.DataSource = rolesArray
      RolesListBox.DataBind()
    End If

  End Sub


  Public Sub DeleteRole_OnClick(ByVal sender As Object, ByVal args As EventArgs)

    Dim delRole As String

    Try
      delRole = RolesListBox.SelectedItem.Value

      Roles.DeleteRole(delRole)

      Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' deleted."

      ' Re-bind roles to ListBox.

      rolesArray = Roles.GetAllRoles()
      RolesListBox.DataSource = rolesArray
      RolesListBox.DataBind()
    Catch
      Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' <u>not</u> deleted."
    End Try

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Sample: Delete Role</title>
</head>
<body>
  <form runat="server" id="PageForm">
    <h3>
      Delete Role</h3>
    <asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
    <table border="0">
      <tr>
        <td valign="top">
          Delete Role:</td>
        <td valign="top">
          <asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
        <td valign="top">
          <asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
      </tr>
    </table>
  </form>
</body>
</html>

설명

이 메서드는 DeleteRole 데이터 원본에서 역할 이름을 제거합니다. DeleteRoleDeleteRole 기본 역할 공급자의 메서드를 호출하여 데이터 원본에서 지정된 역할을 제거합니다.

throwOnPopulatedRole경우 true 예외가 throw되고 매개 변수로 식별되는 roleName 역할에 하나 이상의 멤버가 있는 경우 역할이 삭제되지 않습니다. 이 throwOnPopulatedRole경우 false 역할이 비어 있는지 여부에 관계없이 삭제됩니다.

추가 정보

적용 대상

DeleteRole(String)

데이터 원본에서 역할을 제거합니다.

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

매개 변수

roleName
String

삭제할 역할의 이름입니다.

반품

데이터 원본에서 삭제되었으면 />이고, 그렇지 않으면 .

예외

roleNamenull입니다.

roleName 가 빈 문자열이거나 쉼표(,)를 포함합니다.

roleName 에는 하나 이상의 멤버가 있습니다.

-또는-

역할 관리를 사용할 수 없습니다.

예제

다음 코드 예제에서는 데이터 원본에서 역할을 삭제합니다. 역할 관리를 사용하도록 설정하는 Web.config 파일의 예는 다음을 참조하세요 Roles.


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

  string[] rolesArray;

  public void Page_Load(object sender, EventArgs args)
  {
    if (!IsPostBack)
    {
      // Bind roles to ListBox.

      rolesArray = Roles.GetAllRoles();
      RolesListBox.DataSource = rolesArray;
      RolesListBox.DataBind();
    }
  }


  public void DeleteRole_OnClick(object sender, EventArgs args)
  {
    string delRole = "";

    try
    {
      delRole = RolesListBox.SelectedItem.Value;

      Roles.DeleteRole(delRole);

      Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' deleted.";


      // Re-bind roles to ListBox.

      rolesArray = Roles.GetAllRoles();
      RolesListBox.DataSource = rolesArray;
      RolesListBox.DataBind();
    }
    catch
    {
      Msg.Text = "Role '" + Server.HtmlEncode(delRole) + "' <u>not</u> deleted.";
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Sample: Delete Role</title>
</head>
<body>
  <form runat="server" id="PageForm">
    <h3>
      Delete Role</h3>
    <asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
    <table border="0">
      <tr>
        <td valign="top">
          Delete Role:</td>
        <td valign="top">
          <asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
        <td valign="top">
          <asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
      </tr>
    </table>
  </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">

  Dim rolesArray() As String

  Public Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)

    If Not IsPostBack Then
      ' Bind roles to ListBox.

      rolesArray = Roles.GetAllRoles()
      RolesListBox.DataSource = rolesArray
      RolesListBox.DataBind()
    End If

  End Sub


  Public Sub DeleteRole_OnClick(ByVal sender As Object, ByVal args As EventArgs)

    Dim delRole As String

    Try
      delRole = RolesListBox.SelectedItem.Value

      Roles.DeleteRole(delRole)

      Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' deleted."

      ' Re-bind roles to ListBox.

      rolesArray = Roles.GetAllRoles()
      RolesListBox.DataSource = rolesArray
      RolesListBox.DataBind()
    Catch
      Msg.Text = "Role '" & Server.HtmlEncode(delRole) & "' <u>not</u> deleted."
    End Try

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Sample: Delete Role</title>
</head>
<body>
  <form runat="server" id="PageForm">
    <h3>
      Delete Role</h3>
    <asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
    <table border="0">
      <tr>
        <td valign="top">
          Delete Role:</td>
        <td valign="top">
          <asp:ListBox ID="RolesListBox" runat="server" Rows="8" /></td>
        <td valign="top">
          <asp:Button Text="Delete Role" ID="DeleteRoleButton" runat="server" OnClick="DeleteRole_OnClick" /></td>
      </tr>
    </table>
  </form>
</body>
</html>

설명

이 메서드는 DeleteRole 데이터 원본에서 역할 이름을 제거합니다. DeleteRoleDeleteRole 기본 역할 공급자의 메서드를 호출하여 데이터 원본에서 지정된 역할을 제거합니다.

매개 변수로 roleName 식별된 역할에 하나 이상의 멤버가 있는 경우 예외가 throw되고 역할이 삭제되지 않습니다.

추가 정보

적용 대상