Login.LoggingIn Evento

Definizione

Si verifica quando un utente invia informazioni di accesso, prima che venga eseguita l'autenticazione.

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 evento

Esempio

Nell'esempio di codice seguente viene usato l'evento LoggingIn per assicurarsi che l'utente abbia immesso un indirizzo di posta elettronica ben formato nella UserName proprietà . In caso contrario, l'evento LoggingIn annulla il tentativo di accesso e visualizza un messaggio di errore usando la InstructionText proprietà .

<%@ 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>

Commenti

L'evento LoggingIn viene generato quando un utente invia informazioni di accesso, ma prima che l'utente venga autenticato nel sito Web. Usare l'evento LoggingIn per configurare tutte le informazioni necessarie prima di autenticare un utente.

È possibile annullare un tentativo di accesso durante l'evento LoggingIn impostando la Cancel proprietà dell'oggetto CancelEventArgs su true.

Dopo la generazione dell'evento LoggingIn , il Login controllo genera l'evento Authenticate e quindi l'evento LoggedIn .

Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.

Si applica a

Vedi anche