ClientFormsIdentity.AuthenticationType Propriedade

Definição

Obtém o tipo de autenticação usado para autenticar o usuário.

public:
 property System::String ^ AuthenticationType { System::String ^ get(); };
public string AuthenticationType { get; }
member this.AuthenticationType : string
Public ReadOnly Property AuthenticationType As String

Valor da propriedade

O tipo de autenticação usado para autenticar o usuário.

Implementações

Exemplos

O código de exemplo a seguir demonstra como usar essa propriedade por meio de uma IIdentity referência para determinar se um usuário está atualmente autenticado para serviços de aplicativos cliente. Este exemplo pressupõe que o aplicativo esteja na configuração padrão em que os usuários não precisam fazer logon novamente quando o cookie de autenticação expirar. Caso contrário, o WebException pode indicar que o logon do usuário expirou.

private void SaveSettings()
{
    System.Security.Principal.IIdentity identity = 
        System.Threading.Thread.CurrentPrincipal.Identity;

    // Return if the user is not authenticated.
    if (identity == null || !identity.IsAuthenticated) return;

    // Return if the authentication type is not "ClientForms". 
    // This indicates that the user is not authenticated for 
    // client application services.
    if (!identity.AuthenticationType.Equals("ClientForms")) return;

    try
    {
        Properties.Settings.Default.Save();
    }
    catch (System.Net.WebException)
    {
        MessageBox.Show("Unable to access the Web settings service. " +
            "Settings were not saved on the remote service.", 
            "Not logged in", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
Private Sub SaveSettings()

    Dim identity As System.Security.Principal.IIdentity = _
        System.Threading.Thread.CurrentPrincipal.Identity

    ' Return if the user is not authenticated.
    If identity Is Nothing OrElse Not identity.IsAuthenticated Then Return

    ' Return if the authentication type is not "ClientForms". This indicates
    ' that the user is not authenticated for client application services.
    If Not identity.AuthenticationType.Equals("ClientForms") Then Return

    Try

        My.Settings.Save()

    Catch ex As System.Net.WebException

        MessageBox.Show("Unable to access the Web settings service. " & _
            "Settings were not saved on the remote service.", _
            "Not logged in", MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End Try

End Sub

Comentários

Normalmente, você acessará um ClientFormsIdentity objeto como uma IIdentity referência para evitar uma dependência direta nessa classe. Você pode determinar se um usuário é autenticado verificando a IIdentity.IsAuthenticated propriedade da identidade. No entanto, o usuário pode ser autenticado para Windows, mas não para serviços de aplicativos cliente. Para determinar se o usuário está autenticado para serviços de aplicativo cliente, você também deve confirmar se o valor da IIdentity.AuthenticationType propriedade é "ClientForms". Para obter mais informações, consulte a visão geral da ClientFormsIdentity classe.

Aplica-se a

Confira também