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 オブジェクトに参照としてアクセスします。 ID の プロパティを確認 IIdentity.IsAuthenticated することで、ユーザーが認証されているかどうかを確認できます。 ただし、ユーザーは Windows で認証される可能性がありますが、クライアント アプリケーション サービスでは認証されません。 ユーザーがクライアント アプリケーション サービスに対して認証されているかどうかを判断するには、プロパティ値が "ClientForms" であることを IIdentity.AuthenticationType 確認する必要もあります。 詳細については、クラスの概要に関するページを ClientFormsIdentity 参照してください。

適用対象

こちらもご覧ください