ClientFormsIdentity.IsAuthenticated プロパティ

定義

ユーザーが認証されているかどうかを示す値を取得します。

public:
 property bool IsAuthenticated { bool get(); };
public bool IsAuthenticated { get; }
member this.IsAuthenticated : bool
Public ReadOnly Property IsAuthenticated As Boolean

プロパティ値

ユーザーが認証されている場合は true。それ以外の場合は false

実装

次のコード例では、参照を介してこのプロパティを使用して、 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 参照してください。

適用対象

こちらもご覧ください