728x90
728x170
▶ 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
그리드형(광고전용)
'C# > ASP.NET' 카테고리의 다른 글
[C#/ASP.NET] GridView 클래스 사용하기 (0) | 2019.12.16 |
---|---|
[C#/ASP.NET] WebConfigurationManager 클래스 : 설정 정보 구하기 (0) | 2019.12.16 |
[C#/ASP.NET] ConfigurationManager 클래스 : 설정 정보 구하기 (0) | 2019.12.16 |
[C#/ASP.NET] HttpCachePolicy 클래스 : 코드 기반 캐시 설정하기 (0) | 2019.12.15 |
[C#/ASP.NET] OutputCache 지시자 : 캐시 사용하기 (0) | 2019.12.15 |
[C#/ASP.NET] ASP.NET이 제공하는 상태 관리 기법 (0) | 2019.12.15 |
[C#/ASP.NET] TreeView 클래스 : DataSourceID 속성을 사용해 사이트맵 트리 구조 만들기 (0) | 2019.12.14 |
[C#/ASP.NET] TreeView 클래스 사용하기 (0) | 2019.12.14 |
[C#/ASP.NET] Menu 클래스 : 메뉴 사용하기 (0) | 2019.12.14 |
[C#/ASP.NET] SiteMapPath 클래스 사용하기 (0) | 2019.12.14 |