ClientFormsIdentity.AuthenticationType 屬性

定義

取得用於驗證使用者的驗證類型。

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

屬性值

用於驗證使用者的驗證類型。

實作

範例

下列範例程式碼示範如何透過 IIdentity 參考來使用此屬性,以判斷使用者目前是否已針對用戶端應用程式服務進行驗證。 此範例假設應用程式位於預設設定中,使用者不需要在驗證 Cookie 到期時再次登入。 否則, WebException 可能表示使用者登入已過期。

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

備註

您通常會存取 ClientFormsIdentity 物件做為 IIdentity 參考,以避免直接相依于這個類別。 您可以藉由檢查 IIdentity.IsAuthenticated 身分識別的 屬性來判斷使用者是否已通過驗證。 不過,使用者可能會針對 Windows 進行驗證,但不適用於用戶端應用程式服務。 若要判斷使用者是否已針對用戶端應用程式服務進行驗證,您也應該確認 IIdentity.AuthenticationType 屬性值為 「ClientForms」。 如需詳細資訊,請參閱 類別概 ClientFormsIdentity 觀。

適用於

另請參閱