共用方式為


Login.LoggedIn 事件

定義

發生於使用者登入網站且已經過驗證時。

public:
 event EventHandler ^ LoggedIn;
public event EventHandler LoggedIn;
member this.LoggedIn : EventHandler 
Public Custom Event LoggedIn As EventHandler 

事件類型

範例

下列程式碼範例會 LoggedIn 使用 事件來呼叫網站特定方法,以保留使用者登入的記錄。

<%@ 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">
void SiteSpecificUserLoggingMethod(string UserName)
{
    // Insert code to record the current date and time
    // when this user was authenticated at the site.
}

void OnLoggedIn(object sender, EventArgs e)
{
    SiteSpecificUserLoggingMethod(Login1.UserName);
}
</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" OnLoggedIn="OnLoggedIn"></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">
Sub SiteSpecificUserLoggingMethod(ByVal UserName As String)
    ' Insert code to record the current date and time
    ' when this user was authenticated at the site.
End Sub

Sub OnLoggedIn(ByVal sender As Object, ByVal e As EventArgs)
    SiteSpecificUserLoggingMethod(Login1.UserName)
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" OnLoggedIn="OnLoggedIn"></asp:Login>

        </form>
    </body>
</html>

備註

驗證 LoggedIn 提供者會檢查使用者的認證,並將驗證 Cookie 排入佇列,以在下一個回應中傳送至瀏覽器之後引發此事件。 LoggedIn使用 事件來提供額外的處理,例如在驗證使用者之後存取每個使用者的資料。

當使用者提交其登入資訊時,控制項會 Login 先引發事件、 Authenticate 事件,最後再 LoggedIn 引發 LoggingIn 事件。

注意

當使用者使用 Login 控制項登入網站時,檢視狀態和所有資料都會遺失。 請勿在依賴檢視狀態的事件中 LoggedIn 執行動作。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱