大家看看这个SESSION END事件为何不发生?!
幽幽浮浮 2005-06-20 09:07:03 我写了一小段统计在线人数和总访问人数的源码:
===========aspx.vb============
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Me.Online.Text = "当前在线用户有<font color=red>" + CType(Application("userNum_onLine"), String) + "</font>位"
Me.Visted.Text = "您是本站的第<font color=red>" + CType(Application("userNum_visited"), String) + "</font> 位访问用户 "
End Sub
====================================
===========Global.asax.vb===========
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' 在应用程序启动时激发
Application("userNum_online") = 0
Dim objstream As System.IO.StreamReader = System.IO.File.OpenText(Server.MapPath("userstatic.txt"))
Dim countstring As String
countstring = objstream.ReadLine()
'判断是否为空。如有空,默认为“1”
If countstring = "" Then countstring = "0"
Application("userNum_visited") = CType(countstring, Integer)
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' 在会话启动时激发
Application.Lock()
Application("userNum_online") = CType(Application("userNum_online"), Integer) + 1
Application("userNum_visited") = CType(Application("userNum_visited"), Integer) + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' 在会话结束时激发
Application.Lock()
Application("userNum_online") = CType(Application("userNum_online"), Integer) - 1
Application.UnLock()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' 在应用程序结束时激发
MsgBox("")
Dim objwriter As New System.IO.StreamWriter(Server.MapPath("userstatic.txt"))
objwriter.WriteLine(Application("userNum_visited"))
End Sub
===============================================================
其中的Session_End、Application_End,为何在调试和运行环境中都没有发生啊?!
MSDN上说:Session_OnEnd 事件仅支持进程内会话状态模式。如果您使用状态服务器或 SQL Server 模式,则不会引发该事件。
可是我们默认的不就是进程内会话状态模式嘛!
各位帮忙分析下~~~谢谢了!!