==> [FrmApplicationSession.aspx] 소스 및 디자인 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmApplicationSession.aspx.cs" Inherits="FrmApplicationSession" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

    현재 페이지가 모든 사용자에 의해

    <asp:Label ID="lblApplication" runat="server"></asp:Label>

            번 호출되었습니다.<br />

    현재 페이지가 나에 의해서

    <asp:Label ID="lblSession" runat="server"></asp:Label>

            번 호출했습니다.<br />

    나의 고유 접속번호 :

    <asp:Label ID="lblSessionID" runat="server"></asp:Label><br />

    현재 세션 유지시간 :

    <asp:Label ID="lblTimeout" runat="server"></asp:Label>

       

    </div>

    </form>

</body>

</html>

 




 

 

-------------------------------------------------------------------------------------

 


==> [FrmApplicationSession.aspx.cs] 소스
 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class FrmApplicationSession : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // Application 전역변수 : Public한 전역변수( 1개만 만들수 있다.)

        // Session 전역변수 : Private한 전역변수(사용자별로 여러개 만들 수 있다.)

        //[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();

    }

}

 



-------------------------------------------------------------------------------------

 


[실행결과]






Posted by holland14
: