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

Dim instance As RoleProvider Dim roleName As String Dim returnValue As String() returnValue = instance.GetUsersInRole(roleName)
戻り値
構成済みの applicationName の指定されたロールのメンバであるすべてのユーザーの名前を格納している文字列配列。

GetUsersInRole は Roles クラスの GetUsersInRole メソッドによって呼び出され、ロールに関連付けられているユーザー名をデータ ソースから取得します。構成済みの ApplicationName のロールのみ取得されます。
指定されたロール名が構成済みの applicationName にない場合、または null 参照 (Visual Basic では Nothing) または空の文字列である場合、プロバイダから例外をスローすることをお勧めします。
構成済みの applicationName の指定されたロールに関連付けられているユーザーがない場合、プロバイダから要素のない文字列配列を返すことをお勧めします。

GetUsersInRole メソッドの実装サンプルを次のコード例に示します。
Public Overrides Function GetUsersInRole(rolename As String) As String() If rolename Is Nothing OrElse rolename = "" Then _ Throw New ProviderException("Role name cannot be empty or null.") If Not RoleExists(rolename) Then _ Throw New ProviderException("Role does not exist.") Dim tmpUserNames As String = "" Dim conn As OdbcConnection = New OdbcConnection(connectionString) Dim cmd As OdbcCommand = New OdbcCommand("SELECT Username FROM [" & usersInRolesTable & "]" & _ " WHERE Rolename = ? AND ApplicationName = ?", conn) cmd.Parameters.Add("@Rolename", OdbcType.VarChar, 255).Value = rolename cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName Dim reader As OdbcDataReader = Nothing Try conn.Open() reader = cmd.ExecuteReader() Do While reader.Read() tmpUserNames &= reader.GetString(0) + "," Loop Catch e As OdbcException ' Handle exception. Finally If Not reader Is Nothing Then reader.Close() conn.Close() End Try If tmpUserNames.Length > 0 Then ' Remove trailing comma. tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1) Return tmpUserNames.Split(CChar(",")) End If Return New String() {} End Function
public override string[] GetUsersInRole(string rolename) { if (rolename == null || rolename == "") throw new ProviderException("Role name cannot be empty or null."); if (!RoleExists(rolename)) throw new ProviderException("Role does not exist."); string tmpUserNames = ""; OdbcConnection conn = new OdbcConnection(connectionString); OdbcCommand cmd = new OdbcCommand("SELECT Username FROM [" + usersInRolesTable + "]" + " WHERE Rolename = ? AND ApplicationName = ?", conn); cmd.Parameters.Add("@Rolename", OdbcType.VarChar, 255).Value = rolename; cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName; OdbcDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { tmpUserNames += reader.GetString(0) + ","; } } catch (OdbcException) { // Handle exception. } finally { if (reader != null) { reader.Close(); } conn.Close(); } if (tmpUserNames.Length > 0) { // Remove trailing comma. tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1); return tmpUserNames.Split(','); } return new string[0]; }

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に収録されているすべての辞書からRoleProvider.GetUsersInRole メソッドを検索する場合は、下記のリンクをクリックしてください。

- RoleProvider.GetUsersInRole メソッドのページへのリンク