Bewerken

Delen via


PasswordRecovery.VerifyingUser Event

Definition

Occurs before the user name is validated by the membership provider.

public:
 event System::Web::UI::WebControls::LoginCancelEventHandler ^ VerifyingUser;
public event System.Web.UI.WebControls.LoginCancelEventHandler VerifyingUser;
member this.VerifyingUser : System.Web.UI.WebControls.LoginCancelEventHandler 
Public Custom Event VerifyingUser As LoginCancelEventHandler 

Event Type

Examples

The following code example uses the VerifyingUser event to check whether the submitted user name is formatted as a valid email address. If the user name is not formatted properly, the UserNameInstructionText property is changed to show the error.

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

bool IsValidEmail(string strIn)
{
    // Return true if strIn is in valid email format.
    return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); 
}

void PasswordRecovery1_VerifyingUser(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
    if (!IsValidEmail(PasswordRecovery1.UserName))
    {
        PasswordRecovery1.UserNameInstructionText = "You must enter a valid email address.";
        e.Cancel = true;
    }
    else
    {
            PasswordRecovery1.UserNameInstructionText = "Enter your User Name to receive your password.";
    }
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:passwordrecovery id="PasswordRecovery1" 
        runat="server" 
        onverifyinguser="PasswordRecovery1_VerifyingUser">
      </asp:passwordrecovery>
    </form>
  </body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Function IsValidEmail(ByVal strIn As String) As Boolean
        ' Return true if strIn is in valid email format.
        Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
    End Function

    Sub PasswordRecovery1_VerifyingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
        If Not IsValidEmail(PasswordRecovery1.UserName) Then
            PasswordRecovery1.UserNameInstructionText = "You must enter a valid email address."
            e.Cancel = True
        Else
            PasswordRecovery1.UserNameInstructionText = "Enter your User Name to receive your password."
        End If
    End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:passwordrecovery id="PasswordRecovery1" 
        runat="server" 
        onverifyinguser="PasswordRecovery1_VerifyingUser">
      </asp:passwordrecovery>
    </form>
  </body>
</html>

Remarks

The VerifyingUser event is raised on the server before the user name is submitted to the membership provider to determine whether the user name is valid. Use this event to perform any preprocessing needed on the user name, such as converting it to all uppercase or lowercase letters, or verifying that the user name is in a particular format, such as an email address.

The PasswordRecovery control first raises the VerifyingUser event, and then uses the membership provider specified in the MembershipProvider property to determine whether the user name entered is a valid user name for the Web site. If it is valid, and the membership provider supports password question and answer, the password verification question is returned from the Web site and the PasswordRecovery control displays the Question view. If the user name is not valid, the text in the GeneralFailureText property is displayed in the UserName view so that the user can enter a different user name.

If the membership provider does not support password question and answer, the SendingMail event is raised and email is sent to the user with the new or recovered password.

For more information about handling events, see Handling and Raising Events.

Applies to

See also