共用方式為


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 課程概述。

適用於

另請參閱