Login.LoggingIn Evento

Definición

Se produce cuando un usuario envía información de inicio de sesión, antes de que tenga lugar la autenticación.

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

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se usa el LoggingIn evento para asegurarse de que el usuario ha escrito una dirección de correo electrónico bien formada en la UserName propiedad . Si no es así, el LoggingIn evento cancela el intento de inicio de sesión y muestra un mensaje de error mediante la InstructionText propiedad .

<%@ Page Language="C#" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<!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 OnLoggingIn(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
    if (!IsValidEmail(Login1.UserName))
    {
        Login1.InstructionText = "You must enter a valid email address.";
        e.Cancel = true;
    }
    else
    {
        Login1.InstructionText = String.Empty;
    }
}

</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:Login id="Login1" runat="server" 
                OnLoggingIn="OnLoggingIn" 
                UserNameLabelText="Email Address:" 
                UserNameRequiredErrorMessage="Email Address.">
            </asp:Login>
        </form>
    </body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<!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 OnLoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
    If Not IsValidEmail(Login1.UserName) Then
        Login1.InstructionText = "You must enter a valid email address."
        e.Cancel = True
    Else
        Login1.InstructionText = String.Empty
    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:Login id="Login1" runat="server" 
                OnLoggingIn="OnLoggingIn" 
                UserNameLabelText="Email Address:" 
                UserNameRequiredErrorMessage="Email Address.">
            </asp:Login>
        </form>
    </body>
</html>

Comentarios

El LoggingIn evento se genera cuando un usuario envía información de inicio de sesión, pero antes de que el usuario se autentique en el sitio web. Use el LoggingIn evento para configurar cualquier información que necesite antes de autenticar a un usuario.

Puede cancelar un intento de inicio de sesión durante el LoggingIn evento estableciendo la Cancel propiedad del CancelEventArgs objeto trueen .

Una vez generado el LoggingIn evento, el Login control genera el Authenticate evento y, a continuación, el LoggedIn evento .

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.

Se aplica a

Consulte también