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 .      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.

Who is Participating?
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

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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.