AuthenticateEventArgs.Authenticated Proprietà

Definizione

Ottiene o imposta un valore che indica se il tentativo di autenticazione di un utente ha avuto esito positivo.

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

Valore della proprietà

true se il tentativo di autenticazione ha avuto esito positivo, altrimenti false.

Esempio

Nell'esempio di codice seguente viene utilizzata la Authenticated proprietà con uno schema di autenticazione personalizzato per indicare l'esito positivo o negativo del tentativo di accesso di un utente.

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

Commenti

Usare la Authenticated proprietà negli schemi di autenticazione personalizzati implementati nel Login.Authenticate gestore eventi per indicare l'esito positivo o negativo del tentativo di accesso dell'utente.

L'impostazione della Authenticated proprietà su false indica che l'utente del sito Web non ha presentato credenziali valide e il Login controllo deve generare l'evento LoginError oltre a visualizzare il testo che indica che il tentativo di accesso non è riuscito. L'evento LoginError consente allo sviluppatore di pagine di eseguire processi o azioni aggiuntivi quando l'autenticazione utente non riesce. L'impostazione su Authenticatedtrue indica che l'utente ha presentato credenziali valide e il Login controllo deve generare l'evento LoggedIn e reindirizzare l'utente alla pagina corrente o alla pagina indicata da DestinationPageUrl.

Si applica a

Vedi anche