经典ASP:如何列出激活的会话?

时间:2022-04-22 05:38:55

Is there someway to get a list of activated sessions in classic ASP?

有没有办法获得经典ASP中激活的会话列表?

I want to limit the number of simultaneus activated sessions.

我想限制同时激活的会话数。

2 个解决方案

#1


Here is a good article which shows a way to do that: Active User Count Without Global.asa by Josh Painter

这是一篇很好的文章,展示了一种方法:Josh Painter没有Global.asa的活跃用户数

I guess you have to change some details, but this is the way you could approach the problem. The author doesn't use global.asa.

我想你必须改变一些细节,但这是你解决问题的方法。作者不使用global.asa。

A simpler way would be to hook the Sesssion_OnStart and Session_OnEnd events in global.asa and adding/removing the item from the list of sessions implemented as an Application variable.

一种更简单的方法是将global.asa中的Sesssion_OnStart和Session_OnEnd事件挂钩,并从作为Application变量实现的会话列表中添加/删除该项。

If you just want the count of sessions, you could simply doing it this way:

如果你只想要会话数,你可以这样做:

Sub Session_OnStart
   Application.Lock
   Application("count") = Application("count") + 1
   Application.Unlock
End Sub

Sub Session_OnEnd
   Application.Lock
   Application("count") = Application("count") - 1
   If Application("count") < 0 then  ' Could only happen if some other function interfers
      Application("count")=0 
   End If
   Application.Unlock
End Sub

In your ASP file

在您的ASP文件中

<%
Response.Write "There are currently " & Application("count") & "active sessions>"
%>

#2


You can't access one session from another, so there's no built-in way to get a list of all the active sessions. However, you can use Session_OnStart and Session_OnEnd in global.asa to track the sessions by saving the relevant session info to the Application object, a log file, a database etc (depending on exactly what you want to do with the information).

您无法从另一个会话访问一个会话,因此没有内置方法来获取所有活动会话的列表。但是,您可以使用global.asa中的Session_OnStart和Session_OnEnd通过将相关会话信息保存到Application对象,日志文件,数据库等来跟踪会话(具体取决于您要对信息执行的操作)。

We tend to track the number of active sessions in an Application object to get a rough idea of how many people are using a site at any given time (bearing in mind, of course, that people will typically have left the site long before their sessions time out). It's not 100% accurate but it's close enough for a guide to current activity.

我们倾向于跟踪Application对象中活动会话的数量,以便大致了解在任何给定时间有多少人在使用网站(当然,请记住,人们通常会在会话之前很久就离开网站超时)。它不是100%准确,但它足够接近当前活动的指南。

If you just want the number of sessions, you can also use Perfmon to track the Sessions Current counter (and other related counters) for the Active Server Pages performance object. Obviously this assumes access to the server and probably isn't what you want in this case.

如果您只想要会话数,还可以使用Perfmon跟踪Active Server Pages性能对象的Sessions Current计数器(以及其他相关计数器)。显然,这假设访问服务器,在这种情况下可能不是您想要的。

For more info on some options, try this article: How do I count the number of current users / sessions? (archived version)

有关某些选项的更多信息,请尝试以下文章:如何计算当前用户/会话的数量? (存档版)

#1


Here is a good article which shows a way to do that: Active User Count Without Global.asa by Josh Painter

这是一篇很好的文章,展示了一种方法:Josh Painter没有Global.asa的活跃用户数

I guess you have to change some details, but this is the way you could approach the problem. The author doesn't use global.asa.

我想你必须改变一些细节,但这是你解决问题的方法。作者不使用global.asa。

A simpler way would be to hook the Sesssion_OnStart and Session_OnEnd events in global.asa and adding/removing the item from the list of sessions implemented as an Application variable.

一种更简单的方法是将global.asa中的Sesssion_OnStart和Session_OnEnd事件挂钩,并从作为Application变量实现的会话列表中添加/删除该项。

If you just want the count of sessions, you could simply doing it this way:

如果你只想要会话数,你可以这样做:

Sub Session_OnStart
   Application.Lock
   Application("count") = Application("count") + 1
   Application.Unlock
End Sub

Sub Session_OnEnd
   Application.Lock
   Application("count") = Application("count") - 1
   If Application("count") < 0 then  ' Could only happen if some other function interfers
      Application("count")=0 
   End If
   Application.Unlock
End Sub

In your ASP file

在您的ASP文件中

<%
Response.Write "There are currently " & Application("count") & "active sessions>"
%>

#2


You can't access one session from another, so there's no built-in way to get a list of all the active sessions. However, you can use Session_OnStart and Session_OnEnd in global.asa to track the sessions by saving the relevant session info to the Application object, a log file, a database etc (depending on exactly what you want to do with the information).

您无法从另一个会话访问一个会话,因此没有内置方法来获取所有活动会话的列表。但是,您可以使用global.asa中的Session_OnStart和Session_OnEnd通过将相关会话信息保存到Application对象,日志文件,数据库等来跟踪会话(具体取决于您要对信息执行的操作)。

We tend to track the number of active sessions in an Application object to get a rough idea of how many people are using a site at any given time (bearing in mind, of course, that people will typically have left the site long before their sessions time out). It's not 100% accurate but it's close enough for a guide to current activity.

我们倾向于跟踪Application对象中活动会话的数量,以便大致了解在任何给定时间有多少人在使用网站(当然,请记住,人们通常会在会话之前很久就离开网站超时)。它不是100%准确,但它足够接近当前活动的指南。

If you just want the number of sessions, you can also use Perfmon to track the Sessions Current counter (and other related counters) for the Active Server Pages performance object. Obviously this assumes access to the server and probably isn't what you want in this case.

如果您只想要会话数,还可以使用Perfmon跟踪Active Server Pages性能对象的Sessions Current计数器(以及其他相关计数器)。显然,这假设访问服务器,在这种情况下可能不是您想要的。

For more info on some options, try this article: How do I count the number of current users / sessions? (archived version)

有关某些选项的更多信息,请尝试以下文章:如何计算当前用户/会话的数量? (存档版)