Roles.FindUsersInRole メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Roles.FindUsersInRole メソッドの意味・解説 

Roles.FindUsersInRole メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

指定されたロールで、ユーザー名が指定内容と一致するユーザーの一覧を取得します。

名前空間: System.Web.Security
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Shared Function FindUsersInRole
 ( _
    roleName As String, _
    usernameToMatch As String _
) As String()
Dim roleName As String
Dim usernameToMatch As String
Dim returnValue As String()

returnValue = Roles.FindUsersInRole(roleName, usernameToMatch)
public static string[] FindUsersInRole
 (
    string roleName,
    string usernameToMatch
)
public:
static array<String^>^ FindUsersInRole (
    String^ roleName, 
    String^ usernameToMatch
)
public static String[] FindUsersInRole (
    String roleName, 
    String usernameToMatch
)
public static function FindUsersInRole
 (
    roleName : String, 
    usernameToMatch : String
) : String[]

パラメータ

roleName

検索範囲とするロール。

usernameToMatch

検索するユーザー名。

戻り値
ユーザー名が 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 は、構成された applicationName に対して、指定した usernameToMatch に一致するユーザー名を持つロール内のユーザーの一覧を返します。たとえば、usernameToMatch パラメータを "user" に設定すると、"user1"、"user2"、"user3" などが返されます。ユーザーは、ユーザー名のアルファベット順に返されます。

SqlRoleProvider は、usernameToMatch パラメータに対して LIKE 句を使用した検索を実行します。SQL Server の LIKE 句でサポートされる任意のワイルドカードを usernameToMatch パラメータの値に使用できます。

使用例使用例

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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Roles.FindUsersInRole メソッド」の関連用語

Roles.FindUsersInRole メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Roles.FindUsersInRole メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS