I recently posted a comment on insite creations fan page in regards to taking comments to see what modules people wanted or were looking for that have not been developed by insite yet. One requests was to programm a module that showed the number of current users curretly online.
As most of you who work with membership and roles know, there is a method that uses the Membership namespace that graphs the number of users currently logged in.
Sample Code:
Membership.GetNumberOfUsersOnline();
Below you will find the code in which grabs the number of users as well as setting the section title of the module.
UPDATE!
I just updated this module to show the number of visitors viewing your website. This does require an additional step in which you need to alter your GLOBAL.ASAX File to store the information for the number of visitors in real time.
Step 1:
Open the global.asax file and make the following changes(must be type exactly)
global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("OnlineUsers") = 0
End Sub
Sub_Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Application.Lock()
Application("OnlineUsers") = DirectCast(Application("OnlineUsers"), Integer) + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application.Lock()
Application("OnlineUsers") = DirectCast(Application("OnlineUsers"), Integer) - 1
Application.UnLock()
End Sub
Step 2:
Copy all the files in the download exept the "UsersOnline.ascx.resx" to the "/modules/" folder and copy the "UsersOnline.ascx.resx" to the "/modules/App_LocalResources" folder.
Enjoy