Use Application and Session to count online people

2945 단어 application
In the Global.asax global variable file, modify the Session_Start and Session_End methods; the code is as follows:

        protected void Session_Start(object sender, EventArgs e)

        {

            //  

            Session.Timeout = 5; // Session , 

            Application.Lock();

            Application["OnlineCount"] = Convert.ToInt32(Application["OnlineCount"]) + 1;

            Application.UnLock();

        }


        protected void Session_End(object sender, EventArgs e)

        {

            ////  :   Web.config   sessionstate  InProc  ,  Session_End  。
       // StateServer
SQLServer, 。 Application.Lock(); Application["OnlineCount"] = Convert.ToInt32(Application["OnlineCount"]) - 1; Application.UnLock(); }

This can be called on the .aspx page;

<asp:Label ID="labOnlineCount" runat="server"> &nbsp;<font color=red><%=Application["OnlineCount"]%></font>&nbsp; </asp:Label>

좋은 웹페이지 즐겨찾기