2010-10-01 3 views
0

le code de page en cours ci-dessous répertorie les informations de profil de tous les utilisateurs dans mon site. je voudrais le modifier afin qu'il affiche uniquement des informations sur l'utilisateur actuel connecté. Merci.modifier le formulaire pour afficher uniquement les informations utilisateur actuelles, aspnet

---------- ---------- Page ASPX <% @ Page Language = "C#" %> <% @ Import Namespace = "System.Web. sécurité » %>

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>E-mail:</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> 

Répondre

0

Utilisez Membership.GetUser() pour obtenir l'utilisateur actuellement connecté (le cas échéant)

Questions connexes