Login.Authenticate Evento
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Ocorre quando um utilizador é 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 seguinte utiliza o Authenticate evento para chamar código de autenticação personalizado específico do local.
<%@ 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>
Observações
O Authenticate evento é ativado quando um utilizador usa o Login controlo para iniciar sessão num site. Esquemas de autenticação personalizados podem usar o Authenticate evento para autenticar utilizadores.
Note
Quando um utilizador usa o Login controlo para iniciar sessão num site, todos os dados do estado de visualização e todos os dados da publicação são perdidos. Não realize ações Authenticate em eventos que dependam do estado de visualização.
Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.
Notas para Herdeiros
Esquemas de autenticação personalizados devem definir a Authenticated propriedade para true indicar que um utilizador foi autenticado.
Quando um utilizador submete as suas informações de login, o controlo Login primeiro levanta o LoggingIn evento, depois o Authenticate evento e, finalmente, o LoggedIn evento.