Login.LoggingIn 事件
定义
在用户未进行身份验证而提交登录信息时出现。Occurs when a user submits login information, before authentication takes place.
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
事件类型
示例
下面的代码示例使用 LoggingIn 事件确保用户在属性中输入了格式正确的电子邮件地址 UserName 。The following code example uses the LoggingIn event to ensure that the user has entered a well-formed email address in the UserName property. 否则,该 LoggingIn 事件将取消登录尝试并使用属性显示错误消息 InstructionText 。If not, the LoggingIn event cancels the login attempt and displays an error message using the InstructionText property.
<%@ 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>
注解
LoggingIn当用户提交登录信息,但在网站上对用户进行身份验证之前,将引发事件。The LoggingIn event is raised when a user submits login information but before the user is authenticated on the Web site. 在 LoggingIn 对用户进行身份验证之前,使用事件设置所需的任何信息。Use the LoggingIn event to set up any information that you need before authenticating a user.
您可以 LoggingIn 通过将 Cancel 对象的属性设置为来取消事件的登录尝试 CancelEventArgs true 。You can cancel a login attempt during the LoggingIn event by setting the Cancel property of the CancelEventArgs object to true.
LoggingIn引发事件后, Login 控件引发 Authenticate 事件,然后引发 LoggedIn 事件。After the LoggingIn event is raised, the Login control raises the Authenticate event and then the LoggedIn event.
有关处理事件的详细信息,请参阅 处理和引发事件。For more information about handling events, see Handling and Raising Events.