问题
I want to have a list that contains online users in my web site i use this code in local host but it did't shows me any user. Can any body help me? where did i make mistake?
MembershipUserCollection users;
if (!IsPostBack)
{
// Bind users to ListBox.
List<MembershipUser> onlineUsers = new List<MembershipUser>();
foreach (MembershipUser user in Membership.GetAllUsers())
{
if (user.IsOnline)
{
onlineUsers.Add(user);
}
}
ListBox1.DataSource = users;
ListBox1.DataBind();
回答1:
Try changing this line:
ListBox1.DataSource = users;
To this:
ListBox1.DataSource = onlineUsers;
Also do not forget to set the DataKeyField and DataValueField properties on the ListBox1.
来源:https://stackoverflow.com/questions/14214624/list-of-online-users-using-membership-asp-net