This is a simple program that provides Code directly. It mainly modifies the content of the global. asax file...
<% @ Application language = "C #" %>
<SCRIPT runat = "server">
Void application_start (Object sender, eventargs E)
{
// Code that runs when the application starts
// Initialization
Application ["counter"] = 0;
}
Void application_end (Object sender, eventargs E)
{
// Code that runs when the application is closed
}
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
// Lock the application to prevent Parallelism
Application. Lock ();
// Increase the number of online users
Application ["counter"] = (INT) application ["counter"] + 1;
// Unlock
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.
// Lock the application to prevent Parallelism
Application. Lock ();
// Reduce the number of online users
Application ["counter"] = (INT) application ["counter"]-1;
// Unlock
Application. Unlock ();
}
</SCRIPT>
The above are all explained accordingly. in addition, when loading the page, you can assign the application ["counter"] to a control for display. in this way, the number of online users is displayed during page loading.
========================================================== ===
Source: http://www.yxsoft.net.cn/article.asp? Id = 34