×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

在线人数的例子见内,我想同样的方法也可以存用户名。据说Session_OnEnd有时会不工作。

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub

Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 20
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub

Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub

</SCRIPT>
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 请教: 用ASP , 如何实现, for instance , 论坛的当前在线人数,并列出所有当前在线的用户名?能把Dictionary Object 存在Application 里吗?MSDN好像说不行呀.怎么办?
    • Top
    • up
    • 肯定可以,到GOOGLE上SEARCH一下“在线为数统计”就可以发现有很多种方法
    • asp 不熟,不知道啥叫dictionary obj. 不过你建一个表,每登陆一个用户加条纪录,需要列用户时select 一下不就行了吗?
    • 在线人数的例子见内,我想同样的方法也可以存用户名。据说Session_OnEnd有时会不工作。
      <SCRIPT LANGUAGE="VBScript" RUNAT="Server">

      Sub Application_OnStart
      ' Set our user count to 0 when we start the server
      Application("ActiveUsers") = 0
      End Sub

      Sub Session_OnStart
      ' Change Session Timeout to 20 minutes (if you need to)
      Session.Timeout = 20
      ' Set a Session Start Time
      ' This is only important to assure we start a session
      Session("Start") = Now
      ' Increase the active visitors count when we start the session
      Application.Lock
      Application("ActiveUsers") = Application("ActiveUsers") + 1
      Application.UnLock
      End Sub

      Sub Session_OnEnd
      ' Decrease the active visitors count when the session ends.
      Application.Lock
      Application("ActiveUsers") = Application("ActiveUsers") - 1
      Application.UnLock
      End Sub

      </SCRIPT>
      • Thanks . It's simple and straight forward to measure the overall # online like this . But , how to store the unduplicate usernames into the Application object ? The best
        way is to store HASH to Application . That
        s what I'm concerned most . Any idea ?
      • 你这个有问题,人家还要“列出所有当前在线的用户名”,所以最好还是在Application_Onstart中再开一个大的Application数组来存用户,每次用户登录时,先CHECK,再把用户名加入列表。
    • 这段代码不知道能不能WORK,我没试过。
      Set oDict = CreateObject("Scripting.Dictionary")
      '--
      '-- Add items in the dictionary...
      '--
      Application("DICT") = Array(oDict)

      Then, when you need the object you can do like this:

      Set oDict = Application("Dict")(0)