* *********************************** In global. in asax, the following ************************
Start: Protected Void Application_start (Object sender, eventargs E) // This will happen when the current application starts.
{
Sqlconnection con = New Sqlconnection ( " Server =.; database = countpeople; uid = sa; Pwd =; " );
Con. open ();
Sqlcommand cmd = New Sqlcommand ( " Select * From countpeople " , Con );
Int Count = Convert. toint32 (CMD. executescalar ());
Con. Close ();
Application [ " Total " ] = Count; // An application is a global variable and can be operated on by each session.
Application [ " Online " ] = 0 ;
}
Protected Void Session_start (Object sender, eventargs E) // Once the client is connected to the server, this event will occur.
{
Session. Timeout = 1 ;
Application. Lock (); // After the session is locked, only the session can be session
Application [ " Total " ] = ( Int ) Application [ " Total " ] + 1 ;
Application [ " Online " ] = ( Int ) Application [ " Online " ] + 1 ;
Application. Unlock (); // Unlock after session completion
}
End: Protected Void Session_end (Object sender, eventargs E)
{
Application. Lock ();
Application [ " Online " ] = ( Int ) Application [ " Online " ] - 1 ;
Application. Unlock ();
}
Protected Void Application_end (Object sender, eventargs E)
{
Sqlconnection con = New Sqlconnection ( " Server =.; database = countpeople; uid = sa; Pwd =; " );
Con. open ();
Sqlcommand cmd = New Sqlcommand ( " Updata countpeople set num = " + Application [ " Total " ], Con );
Cmd. executenonquery ();
Con. Close ();
}
**************************************** * In the aspx file, the following ********************************* Private Void Page_load ( Object Sender, system. eventargs E)
{
This . Lbltotal. Text = Application [ " Total " ]. Tostring ();
This . Lblonline. Text = Application [ " Online " ]. Tostring ();
// Place user code here to initialize the page
}
Ninetynine original