Online user statistics in ASP.NET

xiaoxiao2021-03-06  70

The role of statistics online users is self-evident, which is to know how much the current user is, and then observe the performance of the server or program according to the number of users, so it can be intuitive to understand the attraction of the website or the efficiency of the website program. Now, we will introduce a simple and clear way to count how much online users. The characteristics of this method are to fully utilize the characteristics of ASP.NET, combined with the Global.asax file, using Application and Session to realize online users, Since only one Application is used in the program, the program occupies system resources can almost neglect, of course, this is also one of the most concerned issues of website managers. First, the user shows the use of the page First, let's take a look at how the number of access users of the current website is as follows: The above code is easy to understand, when the website starts service (when the application starts), the program sets Application [" User_SESSIONS "] is zero, then, when the user enters the website (when the session starts), lock Application, then add Application (" User_SESSIONS "), when the user exits the website, Application (" User_SESSIONS ") minus one . In this way, it is very clever to realize the statistics of online users. Third, a little discussed the above statistics, concise, and the procedure is easy to implement. However, if we carefully consider, it is found that this method has certain limitations, and the number of online users may be slightly a bit error. Because we are in the above programs, we have subtracted from the number of people to the number of people based on the user, and we know that if the user does not close the browser, then enter another website, then this session is in certain Time will not end, this time we can set it through Timeout, general, we set it 20 minutes. Therefore, at the quantity statistics, there is still a little error. Also, we know that in the ASP, if the user sets the cookies above the browser to "disable", then session can no longer be passed, obviously, this setting will make the above statistical procedure. However, we have a solution in ASP.NET, in the config.web file, we will

It is possible to set it to true, but also, you can pass the session without using cookies. In this way, our program can run smoothly in different visitor environments. Fourth, summarizing the above statistical procedures is particularly simple, but the details we don't think of it, this is also what we need to think in programming.

转载请注明原文地址:https://www.9cbs.com/read-82990.html

New Post(0)