The VM does not execute the application_start step. Therefore, make the following modifications in global. asax:
<% @ Application language = " C # " %>
<Script runat="Server">
Void Application_start ( Object Sender, eventargs E)
{
// In the ApplicationProgramTheCode
// Application ["online"] = 10; // Sets the default number of online users, which is not executed in the virtual space.
}
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 unprocessed error occurs
}
Void Session_start ( Object Sender, eventargs E)
{
// Code that runs when a new session is started
Application. Lock ();
If (Application [ " Online " ] = Null ) // In a virtual space, application_start is not executed.
Application [ " Online " ] = 10 ;
Int Online = ( Int ) Application [ " Online " ];
Online ++ ;
Application [ " Online " ] = Online;
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
// In inproc, The session_end event is triggered. If the session mode is set to StateServer
// Or sqlserver.
Application. Lock ();
Int Online = ( Int ) Application [ " Online " ];
Online -- ;
Application [ " Online " ] = Online;
Application. Unlock ();
}
</ Script >
The front-end calls the following method: Current<%=Application ["Online"]%>Person online