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

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

SqlRoleProvider.FindUsersInRole メソッド

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

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

名前空間: System.Web.Security
アセンブリ: 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 override string[] FindUsersInRole (
    string roleName,
    string usernameToMatch
)
public:
virtual array<String^>^ FindUsersInRole (
    String^ roleName, 
    String^ usernameToMatch
) override
public String[] FindUsersInRole (
    String roleName, 
    String usernameToMatch
)
public override 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 が空の文字列です。

または

roleName が 256 文字を超えています。

または

usernameToMatch が 256 文字を超えています。

System.Configuration.Provider.ProviderException

データベースに roleName が見つかりませんでした。

または

データベースとの通信中に不明なエラーが発生しました。

解説解説

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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlRoleProvider クラス
SqlRoleProvider メンバ
System.Web.Security 名前空間
その他の技術情報
ロール管理について



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2026 GRAS Group, Inc.RSS