MembershipUser.LastLoginDate 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用户上次进行身份验证的日期和时间。
public:
virtual property DateTime LastLoginDate { DateTime get(); void set(DateTime value); };
public virtual DateTime LastLoginDate { get; set; }
member this.LastLoginDate : DateTime with get, set
Public Overridable Property LastLoginDate As DateTime
属性值
用户上次进行身份验证的日期和时间。
示例
下面的代码示例显示控件中的所有 ListBox 成员身份用户名,并使用标签显示所选用户名的特定成员身份信息,包括 LastLoginDate 成员资格用户的属性值。
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
MembershipUserCollection users;
public void Page_Load()
{
users = Membership.GetAllUsers();
if (!IsPostBack)
{
// Bind users to ListBox.
UsersListBox.DataSource = users;
UsersListBox.DataBind();
}
// If a user is selected, show the properties for the selected user.
if (UsersListBox.SelectedItem != null)
{
MembershipUser u = users[UsersListBox.SelectedItem.Value];
EmailLabel.Text = u.Email;
IsOnlineLabel.Text = u.IsOnline.ToString();
LastLoginDateLabel.Text = u.LastLoginDate.ToString();
CreationDateLabel.Text = u.CreationDate.ToString();
LastActivityDateLabel.Text = u.LastActivityDate.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: View User Information</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>View User Information</h3>
<table border="0" cellspacing="4">
<tr>
<td valign="top">
<asp:ListBox id="UsersListBox" DataTextField="Username"
Rows="8" AutoPostBack="true" runat="server" />
</td>
<td valign="top">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>Email:</td>
<td><asp:Label runat="server" id="EmailLabel" /></td>
</tr>
<tr>
<td>Is Online?:</td>
<td><asp:Label runat="server" id="IsOnlineLabel" /></td>
</tr>
<tr>
<td>LastLoginDate:</td>
<td><asp:Label runat="server" id="LastLoginDateLabel" /></td>
</tr>
<tr>
<td>CreationDate:</td>
<td><asp:Label runat="server" id="CreationDateLabel" /></td>
</tr>
<tr>
<td>LastActivityDate:</td>
<td><asp:Label runat="server" id="LastActivityDateLabel" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim users As MembershipUserCollection
Public Sub Page_Load()
users = Membership.GetAllUsers()
If Not IsPostBack Then
' Bind users to ListBox.
UsersListBox.DataSource = users
UsersListBox.DataBind()
End If
' If a user is selected, show the properties for the selected user.
If Not UsersListBox.SelectedItem Is Nothing Then
Dim u As MembershipUser = users(UsersListBox.SelectedItem.Value)
EmailLabel.Text = u.Email
IsOnlineLabel.Text = u.IsOnline.ToString()
LastLoginDateLabel.Text = u.LastLoginDate.ToString()
CreationDateLabel.Text = u.CreationDate.ToString()
LastActivityDateLabel.Text = u.LastActivityDate.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: View User Information</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>View User Information</h3>
<table border="0" cellspacing="4">
<tr>
<td valign="top">
<asp:ListBox id="UsersListBox" DataTextField="Username"
Rows="8" AutoPostBack="true" runat="server" />
</td>
<td valign="top">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>Email:</td>
<td><asp:Label runat="server" id="EmailLabel" /></td>
</tr>
<tr>
<td>Is Online?:</td>
<td><asp:Label runat="server" id="IsOnlineLabel" /></td>
</tr>
<tr>
<td>LastLoginDate:</td>
<td><asp:Label runat="server" id="LastLoginDateLabel" /></td>
</tr>
<tr>
<td>CreationDate:</td>
<td><asp:Label runat="server" id="CreationDateLabel" /></td>
</tr>
<tr>
<td>LastActivityDate:</td>
<td><asp:Label runat="server" id="LastActivityDateLabel" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
对于新用户, LastLoginDate 如果用户尚未登录,则 等于 CreationDate 。 如果成功调用 方法,则会 LastLoginDate 更新为 ValidateUser 当前日期和时间。
还可以通过设置 LastLoginDate 的 属性 MembershipUser 并将修改后 MembershipUser 的对象传递给 方法来 UpdateUser 修改上次登录日期。
将 SqlMembershipProvider 、LastLoginDate、 LastActivityDate和 LastPasswordChangedDate 日期设置为CreationDate通过 CreateUser 方法创建成员身份用户的相同日期和时间。