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/
本文介绍了一种使用ASP中的Session计数器监控在线用户数量的方法,并在达到一定阈值时重置计数器及检查文件更新时间,确保定期执行特定任务。
930

被折叠的 条评论
为什么被折叠?



