开发者

code to view current online users is not giving proper output

开发者 https://www.devze.com 2023-03-30 12:26 出处:网络
i have written a code to view online users in asp.net(vb) but when page gets run it doesn\'t show proper output,it only shows 3 users online,if more pages are open then also it shows same.i have paste

i have written a code to view online users in asp.net(vb) but when page gets run it doesn't show proper output,it only shows 3 users online,if more pages are open then also it shows same.i have pasted the code below.please help me.

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_开发者_StackOverflow中文版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


shouldn't that be:

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消