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

Dim instance As WindowsTokenRoleProvider Dim username As String Dim returnValue As String() returnValue = instance.GetRolesForUser(username)
戻り値
指定されたユーザーが属する Windows グループの名前を格納している文字列配列。


このメソッドは、指定したユーザーが属する Windows グループの一覧を Windows オペレーティング システムから取得するために Roles クラスによって呼び出されます。GetRolesForUser メソッドは、LOGON_USER サーバー変数によって識別される現在ログオンしているユーザーに対してのみ呼び出すことができます。username パラメータに指定されている値が現在ログオンしているユーザーの名前ではない場合は、System.Configuration.Provider.ProviderException がスローされます。

GetRolesForUser メソッドを使用して特定のユーザーのロールの一覧を取得し、ロールの一覧を GridView コントロールにバインドするコード例を次に示します。ロール管理を有効にする Web.config ファイルの例については、WindowsTokenRoleProvider のトピックを参照してください。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> Dim rolesArray() As String Public Sub Page_Load() Msg.Text = "" Try If Not Roles.IsUserInRole(User.Identity.Name, "BUILTIN\Administrators") Then Msg.Text = "You are not authorized to view user roles." Return End If Catch e As HttpException Msg.Text = "There is no current logged on user. Role membership cannot be verified." Return End Try ' Bind roles to GridView. rolesArray = Roles.GetRolesForUser(User.Identity.Name) UserRolesGrid.DataSource = rolesArray UserRolesGrid.DataBind() UserRolesGrid.Columns(0).HeaderText = "Roles for " & User.Identity.Name End Sub </script> <html> <head> <title>Sample: View User Roles</title> </head> <body> <form runat="server" id="PageForm"> <h3>View User Roles</h3> <asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR> <table border="0" cellspacing="4"> <tr> <td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid" AutoGenerateColumns="false" Gridlines="None" CellSpacing="0" > <HeaderStyle BackColor="navy" ForeColor="white" /> <Columns> <asp:TemplateField HeaderText="Roles" runat="server" > <ItemTemplate> <%# Container.DataItem.ToString() %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView></td> </tr> </table> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> string[] rolesArray; public void Page_Load() { Msg.Text = ""; try { if (!Roles.IsUserInRole(User.Identity.Name, @"BUILTIN\Administrators")) { Msg.Text = "You are not authorized to view user roles."; return; } } catch (HttpException e) { Msg.Text = "There is no current logged on user. Role membership cannot be verified."; return; } // Bind roles to GridView. rolesArray = Roles.GetRolesForUser(User.Identity.Name); UserRolesGrid.DataSource = rolesArray; UserRolesGrid.DataBind(); UserRolesGrid.Columns[0].HeaderText = "Roles for " + User.Identity.Name; } </script> <html> <head> <title>Sample: View User Roles</title> </head> <body> <form runat="server" id="PageForm"> <h3>View User Roles</h3> <asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR> <table border="0" cellspacing="4"> <tr> <td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid" AutoGenerateColumns="false" Gridlines="None" CellSpacing="0" > <HeaderStyle BackColor="navy" ForeColor="white" /> <Columns> <asp:TemplateField HeaderText="Roles" runat="server" > <ItemTemplate> <%# Container.DataItem.ToString() %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView></td> </tr> </table> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からWindowsTokenRoleProvider.GetRolesForUser メソッドを検索する場合は、下記のリンクをクリックしてください。

- WindowsTokenRoleProvider.GetRolesForUser メソッドのページへのリンク