我编写了一个代码来查看asp.net(vb)中的在线用户,但是当页面运行时它没有显示正确的输出,它只显示3个在线用户,如果有更多的页面打开,那么它也会显示same.i已粘贴下面的代码。请帮助我。
Public Class Global_asax
Inherits System.Web.HttpApplication
Dim i As Integer
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("hitcount") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
i = Application("hitcount")
Application.Lock()
i = i + 1
Application("hitcount") = Application("hitcount") + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Application.Lock()
If Application("hitcount") > 0 Then
Application("hitcount") = Application("hitcount") - 1
Application.UnLock()
End If
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
'Application.UnLock()
End Sub
End Class
答案 0 :(得分:1)
不应该是:
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Application.Lock()
If Application("hitcount") > 0 Then
Application("hitcount") = Application("hitcount") - 1
End If
Application.UnLock() ' <------
End Sub