Solution to the problem that the number of online users uploaded to the VM is not displayed

Source: Internet
Author: User
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

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.