• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

List Users Online "Active Users"

I have a web application ASP.NET
I need to know how can I list the users online? I hope that you can direct me into a solution for this question.

I have a login page login.aspx and this is how I validate the user

        Dim strConnStr As String

        Dim Cnn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;data source=192.xxx.xxx.xxx .      etc......")
        Dim Mycmd As New OleDb.OleDbCommand("select * from users_tbl", Cnn)

        Dr = Mycmd.ExecuteReader()
        While Dr.Read
            If Trim(UCase(Dr("Usercode"))) = Me.txtUserID.Text.ToUpper Then
                If Trim(UCase(Dr("UserPass"))) = Me.txtPassword.Text.ToUpper Then
                    'Now we need to load the sesstion Variables

                    Session("UserID") = Trim(Dr("UserCode")).ToUpper


                End If

            End If
        End While
Is there is a way that I can display a list of all users logged in to the site. If you can provide a sample code it will be greate or direct me to the proper direction.

NOTE: I'm using a SQL server that has users_tbl to validate the user login and I also post the time/date of their login.

  • 5
1 Solution
you could use add a property in the Global.asax.vb/Global.asax.cs which returns a DataTable that holds the users' information. add that as a user logs on and remove that as the user logs off
Imports System.Data

Public Class Global
      Inherits System.Web.HttpApplication
      'table schema
      Private _table As DataTable
      Public ReadOnly Property Users() As DataTable
                  If _table Is Nothing Then
                        _table = New DataTable("Users")
                        With _table.Columns
                              .Item(0).AllowDBNull = False
                              .Item(1).AllowDBNull = False
                              .Item(2).AllowDBNull = False
                              _table.PrimaryKey = New DataColumn() { .Item(0) }
                        End With
                  End If
                  Return _table
            End Get
      End Property
      'standard stuff
End Class
change to
 Private Shared _table As DataTable
 Public Shared ReadOnly Property Users() As DataTable

so now you can add to the data table or remove the entries after log on and log off like so:

Dim userRow As DataRow = Global.Users.Rows.Find(<id>)
If userRow Is Nothing Then
  userRow = Global.Users.NewRow()
  userRow("UserID") = <id>
End If

userRow("Logon") = Now
userRow("Active") = True

If userRow.RowState = DataRowState.Detached Then
End If


when logoff,

Dim userRow As DataRow = Global.Users.Rows.Find(<id>)
If Not userRow Is Nothing Then
End If

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

you could also have a periodic check on the DataTable to flush out any old entries... based on DateTime
wirelessgiantAuthor Commented:

Thank you b1xml2 for a well detail solution.  I have one more question is (I'm not an expert in this)
what is the best way to get the output from Global.Users. .. to get a list of these users and add them to a list box.

I really thank you for your response. :)
to get them to a listbox,

listBox.DataValueField = "UserId"
listBox.DataTextField = "UserName"
listBox.DataSource = Global.Users.DefaultView

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now