ClientFormsAuthenticationMembershipProvider.UserValidated 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在驗證使用者時發生。
public:
event EventHandler<System::Web::ClientServices::Providers::UserValidatedEventArgs ^> ^ UserValidated;
public event EventHandler<System.Web.ClientServices.Providers.UserValidatedEventArgs> UserValidated;
member this.UserValidated : EventHandler<System.Web.ClientServices.Providers.UserValidatedEventArgs>
Public Custom Event UserValidated As EventHandler(Of UserValidatedEventArgs)
Public Event UserValidated As EventHandler(Of UserValidatedEventArgs)
事件類型
範例
下列範例程式代碼示範如何使用這個事件,在窗體的標題列中顯示用戶名稱。
private ClientFormsAuthenticationMembershipProvider formsMembershipProvider =
(ClientFormsAuthenticationMembershipProvider)
System.Web.Security.Membership.Provider;
private String appName = "ClientAppServicesDemo";
private void AttachUserValidatedEventHandler()
{
formsMembershipProvider.UserValidated +=
new EventHandler<UserValidatedEventArgs>(Form1_UserValidated);
}
private void Form1_UserValidated(object sender, UserValidatedEventArgs e)
{
// Set the form's title bar to the application name and the user name.
this.Text = String.Format("{0} ({1})", appName, e.UserName);
}
Private WithEvents formsMembershipProvider As _
ClientFormsAuthenticationMembershipProvider = _
System.Web.Security.Membership.Provider
Private appName As String = "ClientAppServicesDemo"
Private Sub Form1_UserValidated(ByVal sender As Object, _
ByVal e As UserValidatedEventArgs) _
Handles formsMembershipProvider.UserValidated
' Set the form's title bar to the application name and the user name.
Me.Text = String.Format("{0} ({1})", appName, e.UserName)
End Sub
備註
只有在成功驗證用戶之後,才會發生此事件。 您可以使用此事件來更新應用程式,以反映目前的使用者。 例如,您可以使用 UserValidatedEventArgs.UserName 屬性,在應用程式使用者介面中顯示使用者名稱, (UI) 。
您可以呼叫 ClientFormsIdentity.RevalidateUser 方法,以無訊息方式重新驗證使用者。 因此,您應該避免使用 UserValidated 事件來顯示干擾UI。 例如,您不應該使用 UserValidated 事件來顯示歡迎對話方塊。