RoleProvider.GetAllRoles 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
구성된 applicationName
의 모든 역할 목록을 가져옵니다.
public:
abstract cli::array <System::String ^> ^ GetAllRoles();
public abstract string[] GetAllRoles ();
abstract member GetAllRoles : unit -> string[]
Public MustOverride Function GetAllRoles () As String()
반환
- String[]
구성된 applicationName
의 데이터 원본에 저장된 모든 역할의 이름이 포함된 문자열 배열입니다.
예제
다음 코드 예제에서는 메서드의 샘플 구현을 GetAllRoles 보여줍니다.
public override string[] GetAllRoles()
{
string tmpRoleNames = "";
OdbcConnection conn = new OdbcConnection(connectionString);
OdbcCommand cmd = new OdbcCommand("SELECT Rolename FROM Roles " +
" WHERE ApplicationName = ?", conn);
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName;
OdbcDataReader reader = null;
try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
tmpRoleNames += reader.GetString(0) + ",";
}
}
catch (OdbcException)
{
// Handle exception.
}
finally
{
if (reader != null) { reader.Close(); }
conn.Close();
}
if (tmpRoleNames.Length > 0)
{
// Remove trailing comma.
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1);
return tmpRoleNames.Split(',');
}
return new string[0];
}
Public Overrides Function GetAllRoles() As String()
Dim tmpRoleNames As String = ""
Dim conn As OdbcConnection = New OdbcConnection(connectionString)
Dim cmd As OdbcCommand = New OdbcCommand("SELECT Rolename FROM Roles " & _
" WHERE ApplicationName = ?", conn)
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName
Dim reader As OdbcDataReader = Nothing
Try
conn.Open()
reader = cmd.ExecuteReader()
Do While reader.Read()
tmpRoleNames &= reader.GetString(0) & ","
Loop
Catch e As OdbcException
' Handle exception.
Finally
If Not reader Is Nothing Then reader.Close()
conn.Close()
End Try
If tmpRoleNames.Length > 0 Then
' Remove trailing comma.
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1)
Return tmpRoleNames.Split(CChar(","))
End If
Return New String() {}
End Function
설명
GetAllRoles는 클래스의 메서드에 Roles 의해 GetAllRoles 호출되어 데이터 원본에서 역할 이름 목록을 검색합니다. 지정된 ApplicationName 역할에 대한 역할만 검색됩니다.
구성된 applicationName
역할에 대한 역할이 없는 경우 공급자가 요소 없이 문자열 배열을 반환하는 것이 좋습니다.