ClientFormsIdentity.IsAuthenticated 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示是否验证了用户。
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 引用,以避免直接依赖此类。 可以通过检查 IIdentity.IsAuthenticated 标识的 属性来确定是否对用户进行身份验证。 但是,用户可能会对 Windows 进行身份验证,但对于客户端应用程序服务则不进行身份验证。 若要确定用户是否对客户端应用程序服务进行身份验证,还应确认 IIdentity.AuthenticationType 属性值为“ClientForms”。 有关详细信息,请参阅 ClientFormsIdentity 类概述。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈