Pits encountered: Implementation of online user statistics

Source: Internet
Author: User

We use Redis to store the user's information, when the user logs in, we will go to Redis to write this user information.
At the same time, every time the user requests, we go to update the online user's information, update the user's last online date, and delete the expired user's information.

In this way, not real-time, in order to achieve real-time,
We added a JS timer on the page. Every 1s (this time can be set as appropriate)
Sends a request to the server side. Delete the expired user and pull the current online user information.

During this pull, there is a problem when we send the request with a cookie, so that the session status is updated on the server side.
That is, the session will never expire, so that we designed the 30-minute user expired, re-jump to the landing page, the function is affected.

Then we need to solve, in this pull process, update session.
Analyze the code, see the API that this request is walking, and enable the session in the API.
So long as, this interface call does not go this session, is OK.

Modified Code by Analysis:

 Public Override void Init () {this. Postauthenticaterequest + = (sender, e) + ={if (HttpContext.Current.Request.RawUrl.Contains (  "/api/sysmanage/useronline/postlistuserbydepartment")) {return ;} HttpContext.Current.SetSessionStateBehavior (System.Web.SessionState.SessionStateBehavior.Required);}; Base . Init ();}

Note: This place session saves the place and the online user information to save is separate, does the online user clears the comparison time must be consistent with the session expiration time.
This makes online statistics more accurate.

Encountered pits: implementation of online user statistics

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.