Login.LoggedIn 事件

定义

在用户登录到网站并进行身份验证后出现。Occurs when the user logs in to the Web site and has been authenticated.

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

示例

下面的代码示例使用 LoggedIn 事件来调用保留用户登录记录的特定于站点的方法。The following code example uses the LoggedIn event to call a site-specific method that keeps a record of user logins.

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

注解

当身份验证提供程序检查用户的凭据,并且身份验证 cookie 已排队以在下一次响应中发送到浏览器时,将引发 LoggedIn 事件。The LoggedIn event is raised after the authentication provider checks the user's credentials and the authentication cookie is queued to send to the browser in the next response. 在对用户进行身份验证后,可以使用 LoggedIn 事件提供其他处理,如访问每用户数据。Use the LoggedIn event to provide additional processing, such as accessing per-user data, after the user is authenticated.

当用户提交其登录信息时,Login 控件首先引发 LoggingIn 事件、Authenticate 事件,最后引发 LoggedIn 事件。When a user submits his or her login information, the Login control first raises the LoggingIn event, then the Authenticate event, and finally the LoggedIn event.

备注

当用户使用 Login 控件登录到网站时,视图状态和所有 post 数据中的所有数据都将丢失。When a user uses the Login control to log in to a Web site, all data in the view state and all post data is lost. 不要在依赖于视图状态的 LoggedIn 事件中执行操作。Do not perform actions in the LoggedIn event that rely on the view state.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅