How to display online number and location

xiaoxiao2021-03-06  63

I. Principle in Global.asax in .NET is Application_AuthenTentRequest event and Application_BeginRequest events trigger at each access ASPX file. However, the Application_BeginRequest cannot be identified on the identity Ticket ticket that has been verified by the FROMS authentication. So you can only put it in Application_AuthenTicateRequest.

My implementation is: Every time I accepted the ASPX file, I judge whether there is this user (the logged user name that has already logged in, the logged IP address has not been logged in). If there is no existence, the user's identity, final Access time, finally access IP, and the last accessed URL is deposited in the database. If the database has been in the database, the record is updated, updating the last access time, IP, and finally URL.

At the same time, the data deleted in the database with the current time interval for more than 20 minutes (20 minutes without operation is timeout).

Second, the advantage, you can not only see the current number of current online, and you know that those people are online, and whether they are landing, and the number of visitors is already the proportion of members, and the number of people on a page. .

Third, the database structure: the primary key field is empty Type Length Description 1uson_serialint40 No. 0uson_uservarchar200 user name (not landing was IP) 0uson_companyvarchar1000 company name (not landing was 'tourists') 0uson_ip varchar200IP address 0uson_datedatetime80 last operation time of the last operation Page path 0uson_urlvarchar1000

Fourth, the program pays attention: 1. The program is located in Global.asax. 2. I am using Forms Authentication 3, please use system.web.security

protected void Application_AuthenticateRequest (Object sender, EventArgs e) {string strUserID = string.Empty; string strCompany = string.Empty; if (Request.IsAuthenticated) {FormsIdentity identity = (FormsIdentity) User.Identity; FormsAuthenticationTicket ticket = identity.Ticket; strUserID = User.Identity.Name; strcompany = ticket.userdata.split ("|" .tochararray ()) [2];} else {struserid = request.userhostaddress; strCompany = "tourists";

MemberonlineInfo Objonline = New MemberonLineInfo (Struserid, Request.Userhostaddress, Datetime.now.toString (), Request.FilePath, Strcompany;

MEW MEW MEMBERACCOUNT (); if (! Account.checkuseronline (Struserid)) Account.addonline (Objonline); ElseAccount.UpdateOnline (Objonline);

// Remove the timeout member account.deleteonline ();

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

New Post(0)