AuthenticateEventArgs.Authenticated 属性

定义

获取或设置一个指示用户的身份验证尝试是否成功的值。

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

属性值

如果身份验证尝试成功,则为 true;否则为 false

示例

下面的代码示例使用 Authenticated 具有自定义身份验证方案的 属性来指示用户登录尝试成功或失败。

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

注解

Authenticated使用事件处理程序中实现的自定义身份验证方案中的 Login.Authenticate 属性来指示用户登录尝试的成功或失败。

Authenticated将 属性设置为 false 指示网站用户未提供有效凭据,Login并且控件除了显示指示登录尝试未成功的文本外,还应引发 LoginError 事件。 事件 LoginError 使页面开发人员能够在用户身份验证不成功时发生其他进程或操作。 将 设置为 trueAuthenticated 表示用户已提供有效凭据,控件Login应引发 LoggedIn 事件并将用户重定向回当前页或 由 DestinationPageUrl指示的页面。

适用于

另请参阅