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 事件可讓頁面開發人員在使用者驗證未成功時發生其他進程或動作。 設定 Authenticatedtrue 表示使用者已呈現有效的認證,而且 Login 控制項應該引發 LoggedIn 事件,並將使用者重新導向回目前頁面或 所 DestinationPageUrl 指示的頁面。

適用於

另請參閱