Online statistics and tracking (new)

Source: Internet
Author: User

When performing online user statistics and tracking, it is found that there is always a statistical error,
Check the old version. The number of online users is always greater than the actual number of online users. The test is performed several times. The reason is that the exited session does not expire immediately. The timeout setting of the session is too long. After the page is closed, the sessionid is not deleted. I tried it many times and finally found a method that immediately invalidates the session after the browser is closed.

This version simulates the first trace after a user logs on. Download here:
I made the following changes:
1. When a logon jump is made, the existing user name will be passed into the cache and the user name will be updated.
Userinfo uinfo = new userinfo ();
Uinfo. sessionid = This. session. sessionid;
If (httpcontext. Current. cache [uinfo. cachekey]! = NULL)
{
(Userinfo) httpcontext. Current. cache [uinfo. cachekey]). Username = textbox1.text. Trim ();
}

2. When you close the page after logging on, call the client onUnload = "removeline ()" and execute the following function:
<Script language = "JavaScript">
Function removeline () {If (event. clientx <0 & event. clienty <0)
{
Document. write ('<IFRAME width = "100" Height = "100" src = "removesession. aspx "> </iframe> <object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object> '); document. all. webbrowser. execwb (45, 1 );
}
}
</SCRIPT>
The onUnload Event determines that the page_load event in removesession. aspx is executed when the event is closed.
In removesession. aspx, page_load and execute the following statement:
Session. removeall ();
Session. Abandon ();
If (httpcontext. Current. cache [This. session. sessionid]! = NULL)
{Httpcontext. Current. cache. Remove (this. session. sessionid );
}

After this modification, the sessionid in the cache is manually deleted, so that the online statistics are finally accurate, so I'm a little angry :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.