AuthenticateEventArgs.Authenticated Propiedad

Definición

Obtiene o establece un valor que indica si el intento de autenticación de un usuario ha tenido éxito.

public:
 property bool Authenticated { bool get(); void set(bool value); };
public bool Authenticated { get; set; }
member this.Authenticated : bool with get, set
Public Property Authenticated As Boolean

Valor de propiedad

Es true si el intento de autenticación ha sido correcto; en caso contrario, es false.

Ejemplos

En el ejemplo de código siguiente se usa la Authenticated propiedad con un esquema de autenticación personalizado para indicar el éxito o error del intento de inicio de sesión de un usuario.

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

Comentarios

Use la Authenticated propiedad en esquemas de autenticación personalizados implementados en el Login.Authenticate controlador de eventos para indicar el éxito o error del intento de inicio de sesión del usuario.

Establecer la Authenticated propiedad en false indica que el usuario del sitio web no ha presentado credenciales válidas y que el Login control debe generar el LoginError evento además de mostrar texto que indica que el intento de inicio de sesión no se realizó correctamente. El LoginError evento permite al desarrollador de páginas tener procesos o acciones adicionales cuando la autenticación del usuario no se realiza correctamente. Establecer Authenticated en true indica que el usuario ha presentado credenciales válidas y el Login control debe generar el LoggedIn evento y redirigir al usuario de nuevo a la página actual o a la página indicada por DestinationPageUrl.

Se aplica a

Consulte también