Login.Authenticate Login.Authenticate Login.Authenticate Login.Authenticate Event

定义

验证用户的身份后出现。Occurs when a user is authenticated.

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事件以调用特定于站点的自定义身份验证代码。The following code example uses the Authenticate event to call site-specific custom authentication code.

<%@ 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中登录到网站上的控件。The Authenticate event is raised when a user uses the Login control to log in to a Web site. 可以使用自定义身份验证方案Authenticate事件用户进行身份验证。Custom authentication schemes can use the Authenticate event to authenticate users.

备注

当用户使用Login控件中登录到网站时,视图状态中的所有数据和所有 post 数据会丢失。When a user uses the Login control to log in to a Web site, all data in the view state and all post data is lost. 不执行中的操作Authenticate根据视图状态的事件。Do not perform actions in the Authenticate event that rely on the view state.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

继承者说明

应设置自定义身份验证方案Authenticated属性设置为true以指示用户已经过身份验证。Custom authentication schemes should set the Authenticated property to true to indicate that a user has been authenticated.

当用户提交他或她的登录信息,Login控件首先引发LoggingIn事件,则Authenticate事件,并最后LoggedIn事件。When a user submits his or her login information, the Login control first raises the LoggingIn event, then the Authenticate event, and finally the LoggedIn event.

适用于

另请参阅