Insus.net the development of such a multi-site, customers have not this requirement. However, now there are customers have such a request.
Online user access, that is, to write a counter for the site, the initial value of the counter is 0, when the site started running (Application_Start), the start of statistics, when there is a user access (Session_Start) counter plus 1, when the user access to leave ( Session_End) counter minus 1.
In the Web site, there is a file called Global.asax:
At the beginning of the program, define a counter with an initial value of 0
Sub Application_Start (ByValasObjectByVal as EventArgs) ' Code that runs on application startup Application ("onlinevisitors"0 End Sub
View Code
When a user visits a website:
SubSession_Start (ByValSender as Object,ByValE asEventArgs)'Code that runs when a new session is startedApplication.Lock () application ("onlinevisitors") =DirectCast(Application ("onlinevisitors"),Integer) +1Application.UnLock ()End Sub
View Code
When a user leaves the site:
SubSession_End (ByValSender as Object,ByValE asEventArgs)'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 SQL Server, the event is not raised.Application.Lock () application ("onlinevisitors") =DirectCast(Application ("onlinevisitors"),Integer) -1Application.UnLock ()End Sub
View Code
Of the above two Session_Start and Session_End methods, Insus.net has the use of Application.Lock and Application.UnLock method, is to prevent multiple threads at the same time change this variable, when changing the counter, first lock it up, notconsistent complete, and then unlock.
To save the Global.asax file, you need to show the location of the number of online visitors on the Web page:
<% = Application ("onlinevisitors"). ToString ()%>
During the test, the insus.net used two browsers to make the site get different process visitors. While each browser opens a different window, the data variable is obtained.
Postscript:
This method, only to do surface Kung Fu, statistics can not really online visitors. If you need to really achieve online demographics, you need to get the other parameters of the visitor to make a judgment.
The website needs to show the number of online visitors