2011-08-25 61 views
0

我已經編寫了一個代碼來查看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 

回答

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 
相關問題