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 首先引发 LoggingIn 事件,然后引发 Authenticate 事件,最后引发 LoggedIn 事件。

注意

当用户使用 Login 控件登录到网站时,处于视图状态的所有数据和所有发布数据都将丢失。 请勿在依赖于视图状态的事件中 LoggedIn 执行操作。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅