ClientFormsIdentity.RevalidateUser 메서드

정의

캐시된 자격 증명을 사용하여 자동으로 사용자를 인증합니다.

public:
 void RevalidateUser();
public void RevalidateUser ();
member this.RevalidateUser : unit -> unit
Public Sub RevalidateUser ()

예제

다음 예제 코드에서는이 메서드를 사용 하 여 애플리케이션을 오프 라인 상태로 유지 하는 경우 사용자를 자동으로 유효성 검사를 하는 방법에 설명 합니다. 이 예제는 CheckedChanged 확인란 값과 일치 하도록 오프 라인 상태를 업데이트 하는 이벤트 처리기입니다. 애플리케이션을 온라인 상태로 설정 하는 사용자, 이벤트 처리기를 다시 사용자 유효성을 검사 하려고 시도 합니다. 그러나 인증 서버를 사용할 수 없는 경우 이벤트 처리기에 애플리케이션을 오프 라인 상태로 반환 합니다.

private void workOfflineCheckBox_CheckedChanged(
    object sender, EventArgs e)
{
    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked;
    if (!ConnectivityStatus.IsOffline)
    {
        try
        {
            // Silently re-validate the user.
            ((ClientFormsIdentity)
                System.Threading.Thread.CurrentPrincipal.Identity)
                .RevalidateUser();

            // If any settings have been changed locally, save the new
            // new values to the Web settings service.
            SaveSettings();

            // If any settings have not been changed locally, check 
            // the Web settings service for updates. 
            Properties.Settings.Default.Reload();
        }
        catch (System.Net.WebException)
        {
            MessageBox.Show(
                "Unable to access the authentication service. " +
                Environment.NewLine + "Staying in offline mode.",
                "Warning", MessageBoxButtons.OK, 
                MessageBoxIcon.Warning);
            workOfflineCheckBox.Checked = true;
        }
    }
}
Private Sub workOfflineCheckBox_CheckedChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles workOfflineCheckBox.CheckedChanged

    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked
    If Not ConnectivityStatus.IsOffline Then

        Try

            ' Silently re-validate the user.
            CType(System.Threading.Thread.CurrentPrincipal.Identity,  _
                ClientFormsIdentity).RevalidateUser()

            ' If any settings have been changed locally, save the new
            ' new values to the Web settings service.
            SaveSettings()

            ' If any settings have not been changed locally, check 
            ' the Web settings service for updates. 
            My.Settings.Reload()

        Catch ex As System.Net.WebException

            MessageBox.Show( _
                "Unable to access the authentication service. " & _
                Environment.NewLine + "Staying in offline mode.", _
                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            workOfflineCheckBox.Checked = True

        End Try

    End If
End Sub

설명

폼 인증을 사용 하 여 현재 사용자의 유효성을 검사 하는 경우는 ClientFormsIdentity 클래스는 애플리케이션 실행 되는 사용자 자격 증명을 저장 합니다. 그러나 사용자가 인증 쿠키가 만료 될 때까지만 인증 됩니다. 쿠키가 만료 된 후 원격 역할 또는 웹 설정 서비스에 액세스 하는 사용자 유효성을 재검사 해야 합니다. 서비스용 고급 설정 대화 상자를 사용하여 자동으로 사용자 유효성을 다시 검사하도록 애플리케이션을 구성할 수 있습니다. 그러나 쿠키 만료를 적용 하도록 애플리케이션을 구성 하는 경우 있습니다 수 프로그래밍 방식으로 유효성을 다시 검사를 호출 하 여는 RevalidateUser 메서드. 이 메서드는 또한 유용 오프 라인 모드에서 온라인 모드로 전환 하는 경우 애플리케이션 종료 때문에 동안 오프 라인입니다.

참고

RevalidateUser 메서드는 편의상의 목적으로만 사용됩니다. 반환 값이 없기 때문에 유효성 재검사가 실패했는지 여부를 나타낼 수 없습니다. 예를 들어 서버에서 사용자 자격 증명이 변경된 경우 유효성 재검사가 실패할 수 있습니다. 이 경우 서비스 호출이 실패한 후 명시적으로 사용자의 유효성을 검사하는 코드를 포함하는 것이 좋습니다. 자세한 내용은 웹 설정 액세스 섹션을 참조 하세요 연습: 클라이언트 애플리케이션 서비스를 사용 하 여입니다.

적용 대상

추가 정보