用global.asa来实现在特定条件执行特定的ASP程序(转)

本文介绍了一种使用ASP中的Session计数器监控在线用户数量的方法,并在达到一定阈值时重置计数器及检查文件更新时间,确保定期执行特定任务。
SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart
Application("SessionCount") = 0
End Sub

Sub Session_OnStart

Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock

If Application("SessionCount") > 100 Then

Application.Lock
Application("SessionCount") = 0
Application.Unlock

' Here you would put any code you need to run
' do not surround the code with tags
' For example you might run a database query that checks for expired accounts
End if

End Sub

global.asa例子二

Sub Application_OnStart
Application("SessionCount") = 0
End Sub

Sub Session_OnStart

Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock

If Application("SessionCount") > 15 Then

Application.Lock
Application("SessionCount") = 0
Application.Unlock

Set ObjMyFile = CreateObject("Scripting.FileSystemObject")
Set OpenMyFile = ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))MyFileValue = OpenMyFile.ReadLine
OpenMyFile.Close
  
  If DateDiff("h",MyFileValue,NOW) > 6 Then

     ' Here you would put any code you need to run
     ' do not surround the code with <% %> tags
     ' For example you might run a database query that checks for expired accounts
      
      Set WriteMyFile = ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt"))
      WriteMyFile.WriteLine(NOW)
      WriteMyFile.Close
  
  End if
End If

End Sub


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124712/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124712/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值