홈 · 개발 참고자료

개발 참고자료

[ASP.NET] Counter

작성자
관리자
작성일
2016-08-31
조회
6782
분류
ASP.NET
======================================================= FrmCounter.aspx ======================================================= <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FrmCounter.aspx.cs" Inherits="DevCounter.FrmCounter" %> 카운터 표시
현재:
======================================================= FrmCounter.aspx.cs ======================================================= using System; namespace DevCounter { public partial class FrmCounter : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 현재 접속자 수 표시 lblNow.Text = Application["CurrentVisit"].ToString(); } } } ======================================================= Global.asax.cs ======================================================= using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; namespace DevCounter { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { //[1] 사이트 통계 1/3 Application["CurrentVisit"] = 0; // 현재 사용자 } protected void Session_Start(object sender, EventArgs e) { //[2] 사이트 통계 2/3 Application.Lock(); Application["CurrentVisit"] = Convert.ToInt32(Application["CurrentVisit"]) + 1; // 현재 사용자 Application.UnLock(); } protected void Session_End(object sender, EventArgs e) { //[3] 사이트 통계 3/3 Application.Lock(); Application["CurrentVisit"] = (int)Application["CurrentVisit"] - 1; // 현재 사용자 Application.UnLock(); } protected void Application_End(object sender, EventArgs e) { // Empty } } }