使用英语阅读

通过


Login.LoggingIn 事件

定义

在用户未进行身份验证而提交登录信息时出现。

public event System.Web.UI.WebControls.LoginCancelEventHandler LoggingIn;

事件类型

示例

下面的代码示例使用 LoggingIn 事件来确保用户在 属性中 UserName 输入了格式正确的电子邮件地址。 否则,事件 LoggingIn 将取消登录尝试并使用 属性显示错误消息 InstructionText

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

注解

当用户 LoggingIn 提交登录信息时,但在用户在网站上进行身份验证之前,将引发 该事件。 使用 LoggingIn 事件设置在对用户进行身份验证之前所需的任何信息。

通过将 对象的 属性设置为 Cancel ,可以在 事件期间LoggingIn取消登录CancelEventArgs尝试。true

LoggingIn引发 事件后,控件LoginAuthenticate引发 事件,然后引发 LoggedIn 事件。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅