Login.Authenticate Evento

Definição

Ocorre quando um usuário é autenticado.

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 

Tipo de evento

Exemplos

O exemplo de código a seguir usa o Authenticate evento para chamar o código de autenticação personalizada específico do site.

<%@ 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>

Comentários

O Authenticate evento é gerado quando um usuário usa o Login controle para fazer logon em um site. Esquemas de autenticação personalizados podem usar o Authenticate evento para autenticar usuários.

Observação

Quando um usuário usa o Login controle para fazer logon em um site, todos os dados no estado de exibição e todos os dados de postagem são perdidos. Não execute ações no Authenticate caso de depender do estado de exibição.

Para obter mais informações sobre como lidar com eventos, consulte Manipulando e gerando eventos.

Notas aos Herdeiros

Os esquemas de autenticação personalizados devem definir a Authenticated propriedade como true para indicar que um usuário foi autenticado.

Quando um usuário envia suas informações de logon, o Login controle primeiro aciona o LoggingIn evento, depois o Authenticate evento e, por fim, o LoggedIn evento.

Aplica-se a

Confira também