Create a global. asax (global application class)
C # code
<SCRIPT runat = "server">
Void application_start (Object sender, eventargs E)
{
//
System. Data. sqlclient. sqlconnection con = dbconnect. createconnection ();
Con. open ();
System. Data. sqlclient. sqlcommand COM = new system. Data. sqlclient. sqlcommand (
"Select * from total", con );
Int COUNT = system. Convert. toint32 (COM. executescalar ());
Con. Close ();
Application ["Total"] = count;
Application ["online"] = 0;
}
Void application_end (Object sender, eventargs E)
{
// Code that runs when the application is closed
System. Data. sqlclient. sqlconnection con = dbconnect. createconnection ();
Con. open ();
System. Data. sqlclient. sqlcommand COM = new system. Data. sqlclient. sqlcommand (
"Update total set num =" + application ["Total"]. tostring (), con );
Com. executenonquery ();
Con. Close ();
}
Void application_error (Object sender, eventargs E)
{
// Code that runs when an unhandled error occurs
}
Void session_start (Object sender, eventargs E)
{
// The code that runs when the new session starts
Session. Timeout = 1;
Application. Lock ();
Application ["Total"] = system. Convert. toint32 (application ["Total"]) + 1;
Application ["online"] = system. Convert. toint32 (application ["online"]) + 1;
Application. Unlock ();
}
Void session_end (Object sender, eventargs E)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the web. config file is set
// The session_end event is triggered only when inproc is used. If the session mode is set to StateServer
// Or sqlserver, the event is not triggered.
Application. Lock ();
Application ["online"] = system. Convert. toint32 (application ["online"])-1;
Application. Unlock ();
}
</SCRIPT>
Read:
Labtotal. Text = application ["Total"]. tostring ();