ClientFormsIdentity.AuthenticationType Proprietà

Definizione

Ottiene il tipo di autenticazione utilizzata per autenticare l'utente.

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

Valore della proprietà

Tipo di autenticazione utilizzata per autenticare l'utente.

Implementazioni

Esempio

Il codice di esempio seguente illustra come usare questa proprietà tramite un IIdentity riferimento per determinare se un utente è attualmente autenticato per i servizi applicazioni client. In questo esempio si presuppone che l'applicazione si trovi nella configurazione predefinita in cui gli utenti non devono accedere di nuovo quando scade il cookie di autenticazione. In caso contrario, potrebbe WebException indicare che l'account di accesso dell'utente è scaduto.

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

Commenti

In genere si accede a un ClientFormsIdentity oggetto come IIdentity riferimento per evitare una dipendenza diretta da questa classe. È possibile determinare se un utente è autenticato controllando la IIdentity.IsAuthenticated proprietà dell'identità. Tuttavia, l'utente può essere autenticato per Windows, ma non per i servizi applicazioni client. Per determinare se l'utente è autenticato per i servizi applicazioni client, è necessario verificare anche che il valore della IIdentity.AuthenticationType proprietà sia "ClientForms". Per altre informazioni, vedere panoramica della ClientFormsIdentity classe.

Si applica a

Vedi anche