Login.LoggingIn 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在用户未进行身份验证而提交登录信息时出现。
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 输入格式正确的电子邮件地址。 否则, 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>
<%@ 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 提交登录信息但在用户在网站上进行身份验证之前,将引发 该事件。 使用 LoggingIn 事件设置在对用户进行身份验证之前所需的任何信息。
可以通过将 LoggingIn 对象的 属性CancelEventArgs设置为 Canceltrue
来取消事件期间的登录尝试。
引发 LoggingIn 事件后,控件将LoginAuthenticate引发 事件,然后引发 LoggedIn 事件。
有关处理事件的详细信息,请参阅 处理和引发事件。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈