Login.Authenticate 事件

定义

验证用户的身份后出现。

public:
 event System::Web::UI::WebControls::AuthenticateEventHandler ^ Authenticate;
public event System.Web.UI.WebControls.AuthenticateEventHandler Authenticate;
member this.Authenticate : System.Web.UI.WebControls.AuthenticateEventHandler 
Public Custom Event Authenticate As AuthenticateEventHandler 

事件类型

示例

下面的代码示例使用 Authenticate 事件调用特定于站点的自定义身份验证代码。

<%@ 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">
private bool SiteSpecificAuthenticationMethod(string UserName, string Password)
{
    // Insert code that implements a site-specific custom 
    // authentication method here.
    //
    // This example implementation always returns false.
    return false;
}

private void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    bool Authenticated = false;
    Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password);

    e.Authenticated = Authenticated;
}

</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"
                OnAuthenticate="OnAuthenticate">
            </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">
Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean
    ' Insert code that implements a site-specific custom 
    ' authentication method here.
    '
    ' This example implementation always returns false.
    Return False
End Function

Sub OnAuthenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
    Dim Authenticated As Boolean
    Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password)

    e.Authenticated = Authenticated
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"
                OnAuthenticate="OnAuthenticate">
            </asp:Login>

        </form>
    </body>
</html>

注解

Authenticate当用户使用 Login 控件登录网站时,将引发 事件。 自定义身份验证方案可以使用 Authenticate 事件对用户进行身份验证。

注意

当用户使用 Login 控件登录到网站时,视图状态中的所有数据和所有发布数据都将丢失。 不要在依赖于视图状态的 事件中 Authenticate 执行操作。

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

继承者说明

自定义身份验证方案应将 Authenticated 属性设置为 true ,以指示用户已经过身份验证。

当用户提交其登录信息时, Login 控件首先引发 LoggingIn 事件,然后 Authenticate 引发 事件,最后 LoggedIn 引发 事件。

适用于

另请参阅