ASPUsers

Show ActiveUsers in webpage using ASP Classic, this also works as an example of using global.asa and application-variables-scope.

CodeFunctionName
What is this?

Public

Tested

Imported
' Place the following code in the Global.asa file in your root directory.

<SCRIPT LANGUAGE="VBScript" RUNAT="Server" >
Sub Application_OnStart
    ' Set active users count to 0 when the server first starts.
    Application("ActiveUsers") = 0
End Sub

Sub Session_OnStart
    ' Set Session Timeout property. We'll set it to 10 minutes.
    Session.Timeout = 10
    ' Lock Application level variable.
    Application.Lock
    ' Increment active users count when a new session starts.
    Application("ActiveUsers") = Application("ActiveUsers") + 1
    Application.UnLock
End Sub

Sub Session_OnEnd
    ' Decrement active users count when a session ends.
    Application.Lock
    Application("ActiveUsers") = Application("ActiveUsers") - 1
    Application.UnLock
End Sub
</SCRIPT >

' Now, all you need to do is display the Application("ActiveUsers") variable on the .asp 'page which you wish to display the number of "active users". For example:


There are presently <% Response.Write Application("ActiveUsers") % > active users.



Views 162

Downloads 83

CodeID
DB ID