Roles.FindUsersInRole(String, String) 메서드

정의

지정된 사용자 이름과 일치하는 부분이 사용자 이름에 포함되어 있는 사용자의 목록을 지정된 역할에서 가져옵니다.

public:
 static cli::array <System::String ^> ^ FindUsersInRole(System::String ^ roleName, System::String ^ usernameToMatch);
public static string[] FindUsersInRole (string roleName, string usernameToMatch);
static member FindUsersInRole : string * string -> string[]
Public Shared Function FindUsersInRole (roleName As String, usernameToMatch As String) As String()

매개 변수

roleName
String

검색할 역할입니다.

usernameToMatch
String

검색할 사용자 이름입니다.

반환

String[]

지정된 역할의 멤버이면서 사용자 이름이 usernameToMatch와 일치하는 모든 사용자의 이름이 포함된 문자열 배열입니다.

예외

roleNamenull(Visual Basic의 경우 Nothing)인 경우

또는

usernameToMatch이(가) null인 경우

roleName이 빈 문자열이거나 쉼표(,)를 포함하는 경우

또는

usernameToMatch이 빈 문자열인 경우

역할 관리가 사용되지 않는 경우

예제

다음 코드 예제에서는 FindUsersInRole 사용자 입력을 기반으로 하는 역할 멤버 자격을 표시 하는 방법입니다. 역할 관리를 사용 하도록 설정 하는 Web.config 파일의 예제를 참조 하세요. Roles합니다.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users</title>
</head>
<body>

<form id="form1" 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>
    <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="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Find Users</title>
</head>
<body>

<form id="form1" 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>
    <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>

설명

FindUsersInRole는 사용자 이름에 구성된 applicationName사용자에 대해 제공된 usernameToMatch 항목과 일치하는 항목이 포함된 역할의 사용자 목록을 반환합니다. 예를 들어 매개 변수가 usernameToMatch "user"로 설정된 경우 사용자 "user1", "user2", "user3" 등이 반환됩니다. 사용자는 사용자 이름으로 사전순으로 반환됩니다.

매개 SqlRoleProvider 변수에 대해 LIKE 절을 사용하여 검색을 usernameToMatch 수행합니다. LIKE 절에서 SQL Server 지원하는 와일드카드는 매개 변수 값에 usernameToMatch 사용할 수 있습니다.

적용 대상