大家好我在互联网Click to see上发布了一个简单的网络应用程序,它可以计算访问者的数量,但它的工作正常但是问题是计数器会保持重置为默认值NO.0 I希望计数器在没有重置的情况下保持它的值,而我在Global.asax中的代码是
<%@ Application Language="VB" %>
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
' Code that runs on application startup
Application("SiteVisitedCounter") = 5000
'to check how many users have currently opened our site write the following line
Application("OnlineUserCounter") = 0
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Application.Lock()
Application("SiteVisitedCounter") = Convert.ToInt32(Application("SiteVisitedCounter")) + 1
'to check how many users have currently opened our site write the following line
Application("OnlineUserCounter") = Convert.ToInt32(Application("OnlineUserCounter")) + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
Application.Lock()
Application("OnlineUserCounter") = Convert.ToInt32(Application("OnlineUserCounter")) - 1
Application.UnLock()
End Sub
和代码背后是
Label3.Text = Application("SiteVisitedCounter").ToString()
Label4.Text = Application("OnlineUserCounter").ToString()