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 类概述。

适用于

另请参阅