Total website visits and current online users

Source: Internet
Author: User

Website creation requires such implementation. I believe that mostProgramIt is easy for colleagues. In fact, as long as we understand the lifecycle of ASP. NET embedded objects, it is easy to think of a solution.

Create in the root directory of the projectGlobal. asaxFile. below is what I wroteCode:

Code

1 Void Application_start ( Object Sender, eventargs E)
2 {
3 // Code that runs when the application starts
4 Application [ " Onlines " ] =   1 ;
5 Try
6 {
7 Application [ " Accesscount " ] = Rs. getdenetlinksort ( "" , " FTYPE = 1 " ). Rows [ 0 ] [ " Faccesscount " ]. Tostring ();
8 }
9 Catch
10 {
11 Application [ " Accesscount " ] =   0 ;
12 }
13 }
14
15 Void Application_end ( Object Sender, eventargs E)
16 {
17 // Code that runs when the application is closed
18 Try
19 {
20 If (Convert. toint32 (application [ " Count " ]) < Convert. toint32 (application [ " Accesscount " ])
21 {
22 Sortedlist SL =   New Sortedlist ();
23 SL. Add ( " FID " , " D49ad538-87ce-4a18-8b70-6d6dc5369b47 " );
24 SL. Add ( " Faccesscount " , Convert. toint32 (application [ " Accesscount " ]);
25 Rs. updateenetlinksort (SL );
26 }
27 New Pbase (). executesql ( Null , " Update creadit_site_allvisit set allvisits = "   + Convert. toint32 (application [ " Accesscount " ]), Sqlresultenum. No );
28 }
29 Catch
30 {
31
32 }
33
34
35 }
36
37 Void Application_error ( Object Sender, eventargs E)
38 {
39 // Code that runs when an unprocessed error occurs
40
41 }
42
43 Void Session_start ( Object Sender, eventargs E)
44 {
45 // Code that runs when a new session is started
46 This . Session. Timeout =   20 ;
47 Application. Lock ();
48 Application [ " Onlines " ] = Convert. toint32 (application [ " Onlines " ]) +   1 ;
49 Application [ " Accesscount " ] = Convert. toint32 (application [ " Accesscount " ]) +   1 ;
50 Try
51 {
52
53 Int Count = Rs. geteenetlinksort ( "" , " FTYPE = 1 " ). Faccesscount;
54 If (Count < Convert. toint32 (application [ " Accesscount " ])
55 {
56 Sortedlist SL =   New Sortedlist ();
57 SL. Add ( " FID " , " D49ad538-87ce-4a18-8b70-6d6dc5369b47 " );
58 SL. Add ( " Faccesscount " , Convert. toint32 (application [ " Accesscount " ]);
59 Rs. updateenetlinksort (SL );
60 }
61 Else
62 {
63 Application [ " Accesscount " ] = Count;
64 }
65 }
66 Catch
67 {
68
69 }
70 Application. Unlock ();
71 }
72
73 Void Session_end ( Object Sender, eventargs E)
74 {
75 // The code that runs when the session ends.
76 // Note: Only the sessionstate mode in the web. config file is set
77 // In inproc, The session_end event is triggered. If the session mode is set to StateServer
78 // Or sqlserver.
79 Application. Lock ();
80 If (Convert. toint32 (application [ " Onlines " ]) <=   0 )
81 Application [ " Onlines " ] =   1 ;
82 Else
83 Application [ " Onlines " ] = Convert. toint32 (application [ " Onlines " ]) -   1 ;
84 Application. Unlock ();
85 }
86

 

Someone may ask why such code exists in the application_end event: If (convert. toint32 (application ["count"]) <convert. toint32 (application ["accesscount"])?

This is because after we launched the system, we found that the total access volume today may be less than the total access volume of the day before yesterday. this problem has not been found. If you have encountered this problem, please answer it!

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.