RolePrincipal.GetRoles メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As RolePrincipal Dim returnValue As String() returnValue = instance.GetRoles
RolePrincipal がメンバになっているロールの一覧。

CacheRolesInCookie が true で、RolePrincipal が示すユーザーのロール名がキャッシュされている場合、GetRoles メソッドはユーザーがメンバになっているキャッシュ内のロール名の一覧を返します。ロール名がキャッシュされていない場合、GetRoles メソッドはユーザーがメンバになっているロール名の一覧を既定のロール Provider から返します。現在の ApplicationName のロール名のみが返されます。ロール名が RolePrincipal オブジェクトにキャッシュされているかどうかを確認するには、IsRoleListCached プロパティをチェックします。

ログオンしているユーザーがメンバになっているロールを表示するコード例を次に示します。
<%@ 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> <headingTextml> <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 runat="server" > <ItemTemplate> <%# Container.DataItem.ToString() %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView></td> </tr> </table> </form> </body> </headingTextml>
<%@ 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> <headingTextml> <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 runat="server" > <ItemTemplate> <%# Container.DataItem.ToString() %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView></td> </tr> </table> </form> </body> </headingTextml>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- RolePrincipal.GetRoles メソッドのページへのリンク