ClientFormsIdentity.AuthenticationType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得用於驗證使用者的驗證類型。
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 類別概觀。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應