첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ Global.asax.cs

using System;
using System.Web;

namespace TestProject
{
    /// <summary>
    /// 글로벌
    /// </summary>
    public class Global : HttpApplication
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 어플리케이션 시작시 처리하기 - Application_Start(sender, e)

        /// <summary>
        /// 어플리케이션 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Application_Start(object sender, EventArgs e)
        {
            Application["UserCount"] = 0;
        }

        #endregion
        #region 세션 시작시 처리하기 - Session_Start(sender, e)

        /// <summary>
        /// 세션 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();

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

            Application.UnLock();
        }

        #endregion
        #region 세션 종료시 처리하기 - Session_End(sender, e)

        /// <summary>
        /// 세션 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();

            Application["UserCount"] = (int)Application["UserCount"] - 1;

            Application.UnLock();
        }

        #endregion
        #region 어플리케이션 종료시 처리하기 - Application_End(sender, e)

        /// <summary>
        /// 어플리케이션 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Application_End(object sender, EventArgs e)
        {
        }

        #endregion
    }
}

 

728x90

 

▶ MainPage.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Page 클래스 : Application 속성을 사용해 현재 접속자 수 표시하기</title>
    </head>
    <body>
        <form id="form" runat="server">
            <div>
                현재 접속자 수 : <asp:Label ID="userCountLabel" runat="server" />
            </div>
        </form>
    </body>
</html>

 

300x250

 

▶ MainPage.aspx.cs

using System;
using System.Web.UI;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 페이지 로드시 처리하기 - Page_Load(sender, e)

        /// <summary>
        /// 페이지 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.userCountLabel.Text = ((int)Application["UserCount"]).ToString("#,##0");
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,