다음을 통해 공유


AuthorizationStoreRoleProvider.DeleteRole(String, Boolean) 메서드

정의

권한 부여 관리자 정책 저장소에서 역할을 제거합니다.

public:
 override bool DeleteRole(System::String ^ roleName, bool throwOnPopulatedRole);
public override bool DeleteRole (string roleName, bool throwOnPopulatedRole);
override this.DeleteRole : string * bool -> bool
Public Overrides Function DeleteRole (roleName As String, throwOnPopulatedRole As Boolean) As Boolean

매개 변수

roleName
String

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

throwOnPopulatedRole
Boolean

true이면 roleName에 하나 이상의 멤버가 있을 때 예외를 throw합니다.

반환

Boolean

역할이 삭제되었으면 true이고, 그렇지 않으면 false입니다.

예외

roleName이(가) null인 경우

roleName이 빈 문자열인 경우

또는 roleName에 쉼표가 포함된 경우

roleName에 하나 이상의 멤버가 있고 throwOnPopulatedRoletrue인 경우

또는 구성된 applicationName을 찾을 수 없는 경우

또는 구성된 scopeName을 찾을 수 없는 경우

또는 권한 부여 관리자 런타임이 서버에 설치되어 있지 않은 경우

connectionStringName 특성이 존재하지 않는 파일에 대한 연결 문자열을 참조할 경우

AuthorizationStoreRoleProvider 인스턴스가 파일 기반 정책 저장소를 사용하여 구성되어 있고 해당 파일에 대한 읽기 권한이 현재 신뢰 수준에서 허용되지 않는 경우

예제

다음 예제에서는 권한 부여 관리자 정책 저장소에서 역할을 삭제 합니다. 역할 관리를 사용 하도록 설정 하는 Web.config 파일의 예제를 참조 하세요. AuthorizationStoreRoleProvider합니다.


<%@ 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 메서드를 호출 합니다 Roles ASP.NET 애플리케이션의 구성 파일 (Web.config)에 지정 된 권한 부여 관리자 정책 저장소에서 역할을 삭제 하는 클래스입니다. 역할을 삭제 하면 해당 역할에 연결 된 사용자 목록은 정책 저장소에서도 삭제 됩니다. 데이터베이스에서 사용자 정보를 받지 않습니다.

하는 경우 throwOnPopulatedRole 됩니다 true, 예외가 throw 됩니다 및 역할을 구분 하는 경우 역할 삭제 되지 것입니다는 roleName 매개 변수는 하나 이상의 멤버입니다. 하는 경우 throwOnPopulatedRolefalse, 여부 비어 있는지 여부를 역할 삭제 됩니다.

적용 대상

추가 정보