Login.LoginError 事件

定义

当检测到登录错误时出现。

public:
 event EventHandler ^ LoginError;
public event EventHandler LoginError;
member this.LoginError : EventHandler 
Public Custom Event LoginError As EventHandler 

事件类型

示例

下面的代码示例使用 LoginError 事件在登录尝试失败时向用户显示帮助链接。

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
void OnLoginError(object sender, EventArgs e)
{
    Login1.HelpPageText = "Help with logging in...";
    Login1.CreateUserText = "Create a new user...";
    Login1.PasswordRecoveryText = "Forgot your password?";
}
</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" 
                CreateUserUrl="createUser.aspx" 
                HelpPageUrl="loginHelp.aspx" 
                PasswordRecoveryUrl="getPass.aspx" 
                OnLoginError="OnLoginError">
            </asp:Login>
        </form>
    </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub OnLoginError(ByVal sender As Object, ByVal e As EventArgs)
    Login1.HelpPageText = "Help with logging in..."
    Login1.CreateUserText = "Create a new user..."
    Login1.PasswordRecoveryText = "Forgot your password?"
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" 
                CreateUserUrl="createUser.aspx" 
                HelpPageUrl="loginHelp.aspx" 
                PasswordRecoveryUrl="getPass.aspx" 
                OnLoginError="OnLoginError">
            </asp:Login>
        </form>
    </body>
</html>

注解

LoginError当用户输入的凭据无效时,将引发 该事件。 可以使用 LoginError 事件将用户重定向到自定义错误页、提供其他帮助或记录失败的登录尝试。

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

适用于

另请参阅