Use ASP. NET to display online login users and locations

Source: Internet
Author: User

I. Principles

The Application_AuthenticateRequest event and Application_BeginRequest event in global. asax in. net are triggered every time the aspx file is accessed. However, in Application_BeginRequest, ticket tickets with FROMS authentication cannot be identified. Therefore, it can only be put in Application_AuthenticateRequest.
The implementation principle is: each time you access the aspx file, you will determine whether there is a logged user name in the online table and no recorded IP address). If not, the user's identity, last access time, last access IP address, and last access URL are stored in the database. If the database already exists, update the record to update the last access time, IP address, and last access URL.
At the same time, it is time-out to delete data in the database that is more than 20 minutes away from the current time ).
Ii. Advantages

In this way, you can not only see the exact number of people online, but also know who is online and whether to log on to the website, the proportion of the number of people who are already members, and the location where they are, calculate the number of people on a page.
Iii. Database Structure:

Field Type Length Description
1uson_serial Int 40 Serial number
0uson_user Varchar 200 If the user name is not logged in, it is an IP address)
0uson_company Varchar 1000 If the company name is not logged in, it is 'tourists ')
0uson_ip Varchar 200 IP address
0uson_date Datetime 80 Last operation time
0uson_url Varchar 1000 Last operation page path


4. Procedures
Note:
1. The program is located in global. asax.
2. FORMS authentication
3. 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 );
MemberAccount account = new MemberAccount ();
If (! Account. CheckUserOnline (strUserID ))
Account. AddOnline (objOnline );
Else
Account. UpdateOnline (objOnline );
// Delete the expired Member
Account. DeleteOnline ();
}


Related Article

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.