RolePrincipal.GetRoles 메서드

정의

RolePrincipal이 멤버로 속해 있는 역할 목록을 가져옵니다.Gets a list of roles that the RolePrincipal is a member of.

public:
 cli::array <System::String ^> ^ GetRoles();
public string[] GetRoles ();
member this.GetRoles : unit -> string[]
Public Function GetRoles () As String()

반환

String[]

RolePrincipal이 멤버로 속해 있는 역할 목록입니다.The list of roles that the RolePrincipal is a member of.

예외

Identity 속성은 null입니다.The Identity property is null.

예제

다음 코드 예제는 로그온 한 사용자가 멤버인 역할을 표시 합니다.The following code example displays the roles that the logged-on user is a member of.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">

string[] rolesArray;

public void Page_Load()
{
  RolePrincipal r = (RolePrincipal)User;
  rolesArray = r.GetRoles();
  UserRolesGrid.DataSource = rolesArray;
  UserRolesGrid.DataBind();

  Heading.Text = "Roles for " + User.Identity.Name;
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample: View Roles</title>
</head>
<body>

<form runat="server" id="PageForm">

  <h3><asp:Label id="Heading" runat="server" /></h3>

  <table border="0" cellspacing="4">
    <tr>
      <td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid" 
                                     AutoGenerateColumns="false" Gridlines="None" 
                                     CellSpacing="0" >
                         <Columns>
                           <asp:TemplateField >
                             <ItemTemplate>
                               <%# Container.DataItem.ToString() %>
                             </ItemTemplate>
                           </asp:TemplateField>
                         </Columns>
                       </asp:GridView></td>
    </tr>
  </table>

</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">

Dim rolesArray() As String

Public Sub Page_Load()
  Dim r As RolePrincipal = CType(User, RolePrincipal)
  rolesArray = r.GetRoles()
  UserRolesGrid.DataSource = rolesArray
  UserRolesGrid.DataBind()

  Heading.Text = "Roles for " & User.Identity.Name
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample: View Roles</title>
</head>
<body>

<form runat="server" id="PageForm">

  <h3><asp:Label id="Heading" runat="server" /></h3>

  <table border="0" cellspacing="4">
    <tr>
      <td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid" 
                                     AutoGenerateColumns="false" Gridlines="None" 
                                     CellSpacing="0" >
                         <Columns>
                           <asp:TemplateField >
                             <ItemTemplate>
                               <%# Container.DataItem.ToString() %>
                             </ItemTemplate>
                           </asp:TemplateField>
                         </Columns>
                       </asp:GridView></td>
    </tr>
  </table>

</form>

</body>
</html>

설명

CacheRolesInCookie true 되 고 RolePrincipal가 나타내는 사용자에 대해 역할 이름이 캐시 된 경우 GetRoles 메서드는 캐시에서 사용자가 멤버로 속한 역할 이름 목록을 반환 합니다.If CacheRolesInCookie is true and role names have been cached for the user represented by the RolePrincipal, then the GetRoles method will return the list of role names in the cache that the user is a member of. 역할 이름이 캐시 되지 않은 경우 GetRoles 메서드는 사용자가 기본 역할 Provider에서 멤버로 속해 있는 역할 이름 목록을 반환 합니다.If role names have not been cached, then the GetRoles method returns the list of role names that the user is a member of from the default role Provider. 현재 ApplicationName의 역할 이름만 반환 됩니다.Only role names for the current ApplicationName are returned. 역할 이름이 RolePrincipal 개체에 캐시 되었는지 여부를 확인 하려면 IsRoleListCached 속성을 확인 하십시오.To determine whether role names have been cached in the RolePrincipal object, check the IsRoleListCached property.

적용 대상

추가 정보