ClientFormsIdentity.AuthenticationType Egenskap

Definition

Hämtar den typ av autentisering som används för att autentisera användaren.

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

Egenskapsvärde

Den typ av autentisering som används för att autentisera användaren.

Implementeringar

Exempel

Följande exempelkod visar hur du använder den här egenskapen via en IIdentity referens för att avgöra om en användare för närvarande autentiseras för klientprogramtjänster. Det här exemplet förutsätter att programmet finns i standardkonfigurationen där användarna inte behöver logga in igen när autentiseringscookien upphör att gälla. Annars WebException kan det tyda på att användarens inloggning har upphört att gälla.

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

Kommentarer

Du kommer vanligtvis åt ett ClientFormsIdentity objekt som en IIdentity referens för att undvika ett direkt beroende av den här klassen. Du kan avgöra om en användare autentiseras IIdentity.IsAuthenticated genom att kontrollera identitetens egenskap. Användaren kan dock autentiseras för Windows, men inte för klientprogramtjänster. För att avgöra om användaren autentiseras för klientprogramtjänster bör du även bekräfta att IIdentity.AuthenticationType egenskapsvärdet är "ClientForms". Mer information finns i klassöversikten ClientFormsIdentity .

Gäller för

Se även