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

roleNamenull 参照 (Visual Basic では Nothing) (Visual Basic の場合Nothing) です。

または

usernameToMatchnull 参照 (Visual Basic では Nothing) です。

System.ArgumentException

roleName空の文字列であるか、またはコンマ (,) を含んでます。

または

usernameToMatch空の文字列です。

または

roleName256 文字超えてます。

または

usernameToMatch256 文字超えてます。

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 名前空間
その他の技術情報
ロール管理について



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



SqlRoleProvider.FindUsersInRole メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS