RoleProvider.RoleExists(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 역할 이름이 구성된 applicationName
의 역할 데이터 원본에 이미 있는지 여부를 나타내는 값을 가져옵니다.
public:
abstract bool RoleExists(System::String ^ roleName);
public abstract bool RoleExists (string roleName);
abstract member RoleExists : string -> bool
Public MustOverride Function RoleExists (roleName As String) As Boolean
매개 변수
- roleName
- String
데이터 원본에서 검색할 역할의 이름입니다.
반환
역할 이름이 구성된true
의 데이터 원본에 이미 있으면 applicationName
이고, 그러지 않으면 false
입니다.
예제
다음 코드 예제에서는 메서드의 샘플 구현을 RoleExists 보여줍니다.
public override bool RoleExists(string rolename)
{
if (rolename == null || rolename == "")
throw new ProviderException("Role name cannot be empty or null.");
bool exists = false;
OdbcConnection conn = new OdbcConnection(connectionString);
OdbcCommand cmd = new OdbcCommand("SELECT COUNT(*) FROM Roles " +
" WHERE Rolename = ? AND ApplicationName = ?", conn);
cmd.Parameters.Add("@Rolename", OdbcType.VarChar, 255).Value = rolename;
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName;
try
{
conn.Open();
int numRecs = (int)cmd.ExecuteScalar();
if (numRecs > 0)
{
exists = true;
}
}
catch (OdbcException)
{
// Handle exception.
}
finally
{
conn.Close();
}
return exists;
}
Public Overrides Function RoleExists(ByVal rolename As String) As Boolean
If rolename Is Nothing OrElse rolename = "" Then _
Throw New ProviderException("Role name cannot be empty or null.")
Dim exists As Boolean = False
Dim conn As OdbcConnection = New OdbcConnection(connectionString)
Dim cmd As OdbcCommand = New OdbcCommand("SELECT COUNT(*) FROM Roles " & _
" WHERE Rolename = ? AND ApplicationName = ?", conn)
cmd.Parameters.Add("@Rolename", OdbcType.VarChar, 255).Value = rolename
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName
Try
conn.Open()
Dim numRecs As Integer = CType(cmd.ExecuteScalar(), Integer)
If numRecs > 0 Then
exists = True
End If
Catch e As OdbcException
' Handle exception.
Finally
conn.Close()
End Try
Return exists
End Function
설명
RoleExists는 클래스의 Roles 메서드에 의해 RoleExists 호출되어 구성된 ApplicationName데이터 원본에 역할 이름이 있는지 여부를 확인합니다.
지정된 역할 이름이 null
빈 문자열이거나 빈 문자열인 경우 공급자가 예외를 throw하는 것이 좋습니다.