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

注解

通常以引用的形式IIdentity访问 ClientFormsIdentity 对象,以避免直接依赖此类。 可以通过检查 IIdentity.IsAuthenticated 标识的 属性来确定是否对用户进行身份验证。 但是,用户可能会对 Windows 进行身份验证,但不能针对客户端应用程序服务进行身份验证。 若要确定是否为客户端应用程序服务对用户进行身份验证,还应确认 IIdentity.AuthenticationType 属性值为“ClientForms”。 有关详细信息,请参阅 ClientFormsIdentity 类概述。

适用于

另请参阅