Login Control Question

Discussion in 'ASP.NET / ASP.NET Core' started by danfeather, Apr 9, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Is it possible to populate a drop down list with those people who are currently logged on to your application using the Login Control or any other way?

    Any help would be much appreciated.

    Thanks
     
  2. I've not come across a framework method for doing this..it might exist but I've not seen it yet, however one way I can think of to do it yourself would be to maintain a List<T> of users at login time in your login code, store it in an Application level var and use this when you need to populate your drop down list control.

    Of course if the app recycles you would lose the content of your Application variables so you might need to mirror the List<T> data to your db..how does that model sound?
     
  3. After some more thinking and looking here's a better solution from the MSDN. It looks like the IsOnline property of the MembershipUser class is what you're after.

    <%@ 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>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>
     
  4. There is a better solution to this. I don't really like the default membership due to it's limitation. I'm currently working on Who's online like the one used back in the classic ASP. It check for the number of guest and users currently login. There is also a logic to delete inactive guest/users after 20 mins.

    I built a portal check it out. You may find some interesting code in their.
    http://community.discountasp.net/showthread.php?t=7765
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page