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

Public Overrides Function FindUsersInRole ( _ roleName As String, _ usernameToMatch As String _ ) As String()
Dim instance As SqlRoleProvider Dim roleName As String Dim usernameToMatch As String Dim returnValue As String() returnValue = instance.FindUsersInRole(roleName, usernameToMatch)
public: virtual array<String^>^ FindUsersInRole ( String^ roleName, String^ usernameToMatch ) override
戻り値
usernameToMatch に一致するユーザー名を持ち、指定されたロールのメンバであるすべてのユーザーの名前を格納している文字列配列。

例外の種類 | 条件 |
---|---|
System.ArgumentNullException | roleName が null 参照 (Visual Basic では Nothing) (Visual Basic の場合は Nothing) です。 または usernameToMatch が null 参照 (Visual Basic では Nothing) です。 |
System.ArgumentException | roleName が空の文字列であるか、またはコンマ (,) を含んでいます。 または usernameToMatch が空の文字列です。 または または |
System.Configuration.Provider.ProviderException | または |

FindUsersInRole メソッドは Roles クラスによって呼び出され、構成された applicationName に対して指定された usernameToMatch に一致するユーザー名を持つロール内のユーザーの一覧を返します。SqlRoleProvider は、LIKE キーワードを使用して usernameToMatch パラメータ値と一致するユーザー名を検索し、SQL Server のワイルドカード文字もサポートします。たとえば、usernameToMatch パラメータを "user1" に設定した場合、"user1" のユーザー名が付いたメンバシップ情報が存在していれば、そのメンバシップ情報が返されます。usernameToMatch パラメータを "user%" に設定すると、ユーザー名が "user1"、"user2"、"user_admin" などのユーザーのメンバシップ情報が返されます。

FindUsersInRole メソッドを使用し、ユーザーの入力に基づいてロール メンバシップを表示するコード例を次に示します。ロール管理を有効にする Web.config ファイルの例については、Roles のトピックを参照してください。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> Dim users() As String Public Sub Page_Load() If Not IsPostBack Then RolesListBox.DataSource = Roles.GetAllRoles() RolesListBox.DataBind() End If End SUb Public Sub GoButton_OnClick(sender As Object, args As EventArgs) Msg.Text = "" users = Nothing If RolesListBox.SelectedItem Is Nothing Then Msg.Text = "Please select a role." Return End If users = Roles.FindUsersInRole(RolesListBox.SelectedItem.Text, UsernameTextBox.Text) If users.Length < 1 Then Msg.Text = "No matching users found in selected role." End If UserGrid.DataSource = users UserGrid.DataBind() End Sub </script> <html> <head> <title>Sample: Find Users</title> </head> <body> <form runat="server"> <h3>User List</h3> <asp:Label id="Msg" runat="Server" ForeColor="red" /> <table border=0 cellpadding=3 cellspacing=3> <tr> <td valign=top>Role:</td> <td valign=top><asp:ListBox id="RolesListBox" runat="Server" /></td> </tr> <td valign=top>Username to Search for:</td> <td valign=top><asp:TextBox id="UsernameTextBox" runat="server" /></td> </tr> </table> <asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><BR> <asp:DataGrid id="UserGrid" runat="server" CellPadding="2" CellSpacing="1" Gridlines="Both"> <HeaderStyle BackColor="darkblue" ForeColor="white" /> </asp:DataGrid> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> string[] users; public void Page_Load() { if (!IsPostBack) { RolesListBox.DataSource = Roles.GetAllRoles(); RolesListBox.DataBind(); } } public void GoButton_OnClick(object sender, EventArgs args) { Msg.Text = ""; users = null; if (RolesListBox.SelectedItem == null) { Msg.Text = "Please select a role."; return; } users = Roles.FindUsersInRole(RolesListBox.SelectedItem.Text, UsernameTextBox.Text); if (users.Length < 1) { Msg.Text = "No matching users found in selected role."; } UserGrid.DataSource = users; UserGrid.DataBind(); } </script> <html> <head> <title>Sample: Find Users</title> </head> <body> <form runat="server"> <h3>User List</h3> <asp:Label id="Msg" runat="Server" ForeColor="red" /> <table border=0 cellpadding=3 cellspacing=3> <tr> <td valign=top>Role:</td> <td valign=top><asp:ListBox id="RolesListBox" runat="Server" /></td> </tr> <td valign=top>Username to Search for:</td> <td valign=top><asp:TextBox id="UsernameTextBox" runat="server" /></td> </tr> </table> <asp:Button id="GoButton" Text=" Go " OnClick="GoButton_OnClick" runat="server" /><BR> <asp:DataGrid id="UserGrid" runat="server" CellPadding="2" CellSpacing="1" Gridlines="Both"> <HeaderStyle BackColor="darkblue" ForeColor="white" /> </asp:DataGrid> </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に収録されているすべての辞書からSqlRoleProvider.FindUsersInRole メソッドを検索する場合は、下記のリンクをクリックしてください。

- SqlRoleProvider.FindUsersInRole メソッドのページへのリンク