홈 · 개발 참고자료

개발 참고자료

[ASP.NET] ApplicationSession

작성자
관리자
작성일
2016-08-20
조회
5961
분류
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmApplicationSession.aspx.cs" Inherits="DevASPNET.FrmApplicationSession" %> Application 및 Session 개체
현재 페이지가 모든 사용자에 의해 번 호출되었습니다.
현재 페이지가 나에 의해서 번 호출했습니다.
나의 고유 접속번호 :
현재 세션 유지시간 :
========================================================== using System; namespace DevASPNET { public partial class FrmApplicationSession : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //[1] Application 변수 1 증가 if (Application["Count"] == null) { Application.Lock(); // 먼저 온 사용자가 변수 수정 잠그기 Application["Count"] = 1; // 응용프로그램 변수 선언 및 초기화 Application.UnLock(); // 잠금 해제 : 다른 사용자가 사용 가능 } else { Application["Count"] = (int)Application["Count"] + 1; } //[2] Session 변수 1 증가 if (Session["Count"] == null) { Session["Count"] = 1; // 세션변수 선언과 동시에 1로 초기화 } else { Session["Count"] = (int)Session["Count"] + 1; } //[3] 출력 // 누구나 다 1씩 증가 this.lblApplication.Text = Application["Count"].ToString(); // 현재 접속자만 1씩 증가 this.lblSession.Text = Session["Count"].ToString(); // 현재 접속자의 고유 접속 번호 this.lblSessionID.Text = Session.SessionID; // 현재 세션의 유지 시간 this.lblTimeout.Text = Session.Timeout.ToString(); } } }