MembershipUser.LastActivityDate 属性

定义

获取或设置成员资格用户上次进行身份验证或访问应用程序的日期和时间。Gets or sets the date and time when the membership user was last authenticated or accessed the application.

public:
 virtual property DateTime LastActivityDate { DateTime get(); void set(DateTime value); };
public virtual DateTime LastActivityDate { get; set; }
member this.LastActivityDate : DateTime with get, set
Public Overridable Property LastActivityDate As DateTime

属性值

成员资格用户上次进行身份验证或访问应用程序的日期和时间。The date and time when the membership user was last authenticated or accessed the application.

示例

下面的代码示例显示 ListBox 控件中的所有成员身份用户名,并使用标签显示选定用户名的特定成员身份信息,包括成员资格用户的 LastActivityDate 属性值。The following code example displays all membership user names in a ListBox control and uses labels to show specific membership information for the selected user name, including the LastActivityDate property value for the membership user.

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

注解

用户的 LastActivityDate 将按 CreateUserValidateUser 方法更新为当前日期和时间,并且可以通过 GetUser 方法的某些重载进行更新。The LastActivityDate for a user is updated to the current date and time by the CreateUser and ValidateUser methods, and can be updated by some overloads of the GetUser method. 您可以使用 UpdateUser 方法将 LastActivityDate 属性设置为特定的日期和时间。You can use the UpdateUser method to set the LastActivityDate property to a specific date and time.

LastActivityDate 用于确定用户是否处于联机状态。The LastActivityDate is used to determine whether a user is online. 如果当前日期和时间减去 UserIsOnlineTimeWindow 属性值早于用户 LastActivityDate,则该用户被视为处于联机状态。A user is considered online if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the LastActivityDate for the user.

SqlMembershipProviderCreationDateLastLoginDateLastActivityDateLastPasswordChangedDate 日期设置为通过 CreateUser 方法创建成员资格用户的日期和时间。The SqlMembershipProvider sets the CreationDate, LastLoginDate, LastActivityDate, and LastPasswordChangedDate date to the same date and time when a membership user is created by the CreateUser method.

备注

当从数据源检索或设置用户数据时,System.Web.Profile 中的类和 System.Web.UI.WebControls.WebParts 命名空间中的类将更新用户的 LastActivityDateThe LastActivityDate for a user is updated by the classes in the System.Web.Profile and the System.Web.UI.WebControls.WebParts namespaces whenever user data is retrieved from or set at the data source. 如果你的应用程序使用相同的数据源来存储用户信息,并且你的 ProfileProviderPersonalizationProvider 使用与 MembershipProvider相同的 applicationName 进行配置,则该用户的 LastActivityDateIsOnline 属性将反映此行为。If your application uses the same data source to store user information, and your ProfileProvider and PersonalizationProvider are configured with the same applicationName as your MembershipProvider, then the LastActivityDate and IsOnline properties of the user will reflect this behavior.

适用于

另请参阅