ClientFormsIdentity 类

定义

表示已使用窗体身份验证通过客户端应用程序服务身份验证的用户标识。

public ref class ClientFormsIdentity : IDisposable, System::Security::Principal::IIdentity
public class ClientFormsIdentity : IDisposable, System.Security.Principal.IIdentity
type ClientFormsIdentity = class
    interface IIdentity
    interface IDisposable
Public Class ClientFormsIdentity
Implements IDisposable, IIdentity
继承
ClientFormsIdentity
实现

示例

以下示例代码演示如何在应用程序离开脱机状态时使用此类以无提示方式重新验证用户。 在此示例中,CheckedChanged事件处理程序更新脱机状态以匹配检查框值。 如果用户将应用程序设置为联机状态,则事件处理程序会尝试通过调用 RevalidateUser 方法重新验证用户。 但是,如果身份验证服务器不可用,事件处理程序会将应用程序返回到脱机状态。

注意

RevalidateUser 方法只是为了方便。 因为它没有返回值,所以无法指示重新验证是否失败。 例如,如果在服务器上更改了用户凭据,则重新验证可能会失败。 在这种情况下,你可能要包含在服务调用失败之后显式验证用户的代码。 有关详细信息,请参阅 演练:使用客户端应用程序服务中的访问 Web 设置部分。

private void workOfflineCheckBox_CheckedChanged(
    object sender, EventArgs e)
{
    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked;
    if (!ConnectivityStatus.IsOffline)
    {
        try
        {
            // Silently re-validate the user.
            ((ClientFormsIdentity)
                System.Threading.Thread.CurrentPrincipal.Identity)
                .RevalidateUser();

            // If any settings have been changed locally, save the new
            // new values to the Web settings service.
            SaveSettings();

            // If any settings have not been changed locally, check 
            // the Web settings service for updates. 
            Properties.Settings.Default.Reload();
        }
        catch (System.Net.WebException)
        {
            MessageBox.Show(
                "Unable to access the authentication service. " +
                Environment.NewLine + "Staying in offline mode.",
                "Warning", MessageBoxButtons.OK, 
                MessageBoxIcon.Warning);
            workOfflineCheckBox.Checked = true;
        }
    }
}
Private Sub workOfflineCheckBox_CheckedChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles workOfflineCheckBox.CheckedChanged

    ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked
    If Not ConnectivityStatus.IsOffline Then

        Try

            ' Silently re-validate the user.
            CType(System.Threading.Thread.CurrentPrincipal.Identity,  _
                ClientFormsIdentity).RevalidateUser()

            ' If any settings have been changed locally, save the new
            ' new values to the Web settings service.
            SaveSettings()

            ' If any settings have not been changed locally, check 
            ' the Web settings service for updates. 
            My.Settings.Reload()

        Catch ex As System.Net.WebException

            MessageBox.Show( _
                "Unable to access the authentication service. " & _
                Environment.NewLine + "Staying in offline mode.", _
                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            workOfflineCheckBox.Checked = True

        End Try

    End If
End Sub

注解

客户端应用程序服务功能使用此类来表示经过身份验证的用户。 将应用程序配置为使用客户端应用程序服务和表单身份验证时,可以通过调用 staticMembership.ValidateUser 方法对用户进行身份验证。 身份验证后,可以通过 通过 属性检索到的 的 IPrincipal 属性检索对当前ClientFormsIdentity实例IdentitystaticThread.CurrentPrincipal引用。 有关详细信息,请参阅客户端应用程序服务

通常 ClientFormsIdentity ,你将访问对象作为 IIdentity 引用,以避免直接依赖此类。 可以通过检查 IIdentity.IsAuthenticated 标识的 属性来确定是否对用户进行身份验证。 但是,用户可能会对 Windows 进行身份验证,但对于客户端应用程序服务则不进行身份验证。 若要确定用户是否对客户端应用程序服务进行身份验证,还应确认 IIdentity.AuthenticationType 属性值为“ClientForms”。

必须使用显式 ClientFormsIdentity 引用来调用 RevalidateUser 方法,该方法不是由 IIdentity 接口定义的。

构造函数

ClientFormsIdentity(String, String, MembershipProvider, String, Boolean, CookieContainer)

初始化 ClientFormsIdentity 类的新实例。

属性

AuthenticationCookies

获取从身份验证服务检索到的 Cookie 的集合。

AuthenticationType

获取用于对用户进行身份验证的身份验证类型。

IsAuthenticated

获取一个值,该值指示是否验证了用户。

Name

获取用户的名称。

Provider

获取用于对用户进行身份验证的成员资格提供程序。

方法

Dispose()

释放由 ClientFormsIdentity 使用的所有资源。

Dispose(Boolean)

释放由 ClientFormsIdentity 占用的非托管资源,还可以另外再释放托管资源。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
RevalidateUser()

通过使用缓存凭据来以静默方式验证用户身份。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅