- "폴더추가"에서 "App_Code"폴더를 추가하여 "App_Code"폴더에 "클래스 라이브러리 파일"을 모아서 저장하고,

- "폴더추가"에서 "Bin"폴더를 추가하여 "Bin"폴더에 ".dll"파일을 모아서 저장한다.



Posted by holland14
:



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

 

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

 

<!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:Button ID="btnPostBack" runat="server" Text="다시 게시(PostBack)"

            onclick="btnPostBack_Click" />

        <asp:Button ID="btnNewLoad" runat="server" Text="다시 로드"

            onclick="btnNewLoad_Click" />   

   

    </div>

    </form>

</body>

</html>

 


 


 

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

 


==> [FrmPageLoad.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 FrmPageLoad : System.Web.UI.Page

{

    // 처음 로드(NewLoad)와 다시 게시(PostBack)

    protected void Page_Load(object sender, EventArgs e)

    {

        // 처음 로드된 상태라면

        if (Page.IsPostBack == false) // 다시 게시가 아니라면,

        {

            Response.Write("[1] 처음 로드되었습니다.<br />");

        }

        if (!Page.IsPostBack)

        {

            Response.Write("[2] 처음 로드되었습니다.<br />");

        }

        if (!IsPostBack)

        {

            Response.Write("[3] 처음 로드되었습니다.<br />");

        }

 

        // 다시 게시 상태라면

        if (Page.IsPostBack == true) // 다시 게시된 상태    /  기본값(처음의 값) 'false' 이다.

        {

            Response.Write("[4] 포스트백(다시게시) 되었습니다.<br />");

        }

 

        // 처음로드 <> 다시게시

        if (!Page.IsPostBack)

        {

            Response.Write("[5] 처음 로드되었습니다.<br />");

        }

        else

        {

            Response.Write("[6] 포스트백(다시게시) 되었습니다.<br />");

        }

 

        //[!] Page_Load() 이벤트 처리기는 처음로드하거나 버튼이 클릭할 때마다 실행

        Response.Write("[7] 폼이 로드할 때마다 실행<br />");

    }

 

    protected void btnPostBack_Click(object sender, EventArgs e)

    {

        // Page.ClientScript.RegisterclientScriptBlock() : 자바스크립트 호출

        string strJs = @"

            <script>

                alert('포스트백');

            </script>

        ";

        // Page 생략가능

        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", strJs);

    }

 

    protected void btnNewLoad_Click(object sender, EventArgs e)

    {

        // 현재 페이지로 다시 이동 : 다시 로드

        Response.Redirect(Request.ServerVariables["SCRIPT_NAME"]); //

    }

}

 

 

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

 


[실행결과]



--> 처음 실행화면




--> "다시 게시(PostBack)"버튼을 누른 후 결과





--> "다시 로드"버튼을 누른 후 결과




Posted by holland14
:

 

Page클래스 : Web Form 기반(부모) 클래스

멤버

설명

IsPostBack

현재 페이지가 처음 로드했는지, 다시 게시(PostBack)되었는지 확인

ClientScript.RegisterClientScriptBlock()

자바스크립트를 동적으로 페이지에 추가

Header

현재 폼의 <head> 태그 부분을 정의한다.

Title

현재 폼의 제목을 동적으로 설정하거나 가져온다.

SetFocus()

다른 컨트롤의 ID값을 지정해주면 폼이 로드할 해당 컨트롤에 포커스가 지정된다.




Posted by holland14
:



==> [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
:

 

- Application 개체 : 응용 프로그램 전체 레벨에서 변수 등을 선언, Public 전역변수 선언시. /
   
사이트에 하나의 전역 변수만 생성, 10명이 접속하든 1000명이 접속하든…

멤버

설명

Lock()

애플리케이션 변수를 잠그는 메서드

UnLock()

잠긴 애플리케이션 변수를 해제하는 메서드

Add()

애플리케이션 변수를 만들 사용

Application_Start()

애플리케이션이 시작할 발생( 사이트에 번째 사용자가 방문할 발생). Global.asax에서 설정

Application_End()

응용프로그램이 끝날 발생( 사이트에서 마지막 사용자가 나간 발생). Global.asax에서 설정

 




- Session 개체 : 각각의 사용자별로 변수를 선언하는 등의 기능, Private 전역변수 선언시. /
    웹 사이트에 사용자가 접속할 때마다 동일한 이름으로 사용자별로 전역변수를 만들 있다.

멤버

설명

SessionID

현재 세션의 고유번호 반환

SessionTimeout

세션 시간 기록 : 기본값 20. 추가시키거나 줄일 경우 사용

Abandon()

현재 세션 지우기

Session_Start()

한명의 사용자(세션) 방문할 실행

Session_End()

한명의 사용자가 나간 실행

 




Posted by holland14
:


==> [FrmServerExecute.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 FrmServerExecute : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // 현재 웹폼에 또 다른 웹폼을 추가 : 제어권 돌아옴

        Server.Execute("./FrmRequest.aspx");

 

        Server.Execute("./FrmRequestUserHostAddress.aspx");

 

        // 현재 웹폼에 또 다른 웹폼을 추가 : 제어권 넘김

        Server.Transfer("./FrmResponseWrite.aspx");

 

        // Transfer() = Execute() + Response.End()

        //아래 구문은 실행 안 됨...

        Response.Write("Test");

    }

}

 

  

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

 


[실행결과]





Posted by holland14
:



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

 

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

 

<!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="Label1" runat="server"></asp:Label>

        <br />

        현재 스크립트 파일의 루트(웹서버상주소) 경로 :

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

   

    </div>

    </form>

</body>

</html>

 




 

 

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

 


==> [FrmServerMapPath.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 FrmServerMapPath : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // 현재 웹 폼의 서버측의 물리적 경로

        this.Label1.Text = Server.MapPath("."); // 같은 경로

 

        //현재 스크립트 파일의 루트 경로

        this.Label2.Text =

            Request.ServerVariables["SCRIPT_NAME"];

    }

}


 

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

 


[실행결과]









Posted by holland14
:
 

Server 개체 : 서버측 정보를 확인, HttpServerUtility 클래스의 인스턴스

멤버

설명

MapPath(".")

현재 파일과 같은 경로 반환 : ., ../

Execute()

다른 파일 포함(인클루드) 제어권 돌아옴

Transfer()

다른 파일 포함(인클루드) 제어권 넘김

UrlPathEncode()

넘겨져 쿼리 스트링을 유니코드로 변환(한글 처리)

ScriptTimeout

서버 측에서 현재 ASPX페이지를 초간 처리할 건지 설정


'.NET프로그래밍 > ASP.NET 3.5 SP1' 카테고리의 다른 글

FrmServerExecute  (0) 2009.10.05
FrmServerMapPath  (0) 2009.10.05
FrmRequestUserHostAddress  (0) 2009.10.05
FrmRequest  (0) 2009.10.05
ASP.NET 주요 내장 개체(클래스)들 - Request 개체  (0) 2009.10.05
Posted by holland14
:



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

 

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

 

<!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>

   

        현재 접속자의 IP주소 얻기<br />

        <br />

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

        <br />

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

        <br />

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

   

    </div>

    </form>

</body>

</html>

 




 

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

 


==> [FrmRequestUserHostAddress.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 FrmRequestUserHostAddress : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //현재 접속자의 IP주소를 얻는 3가지 방법

        this.Label1.Text = Request.UserHostAddress;

 

        Label2.Text = Request.ServerVariables["REMOTE_HOST"];

        Label3.Text = Request.ServerVariables["REMOTE_ADDR"];

    }

}

 

 

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

 


[실행결과]






Posted by holland14
:



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

 

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

 

<!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:TextBox ID="UserID" runat="server"></asp:TextBox><br />

        암호 :

        <asp:TextBox ID="Password" runat="server"></asp:TextBox><br />

        이름 :

        <asp:TextBox ID="Name" runat="server"></asp:TextBox><br />

        나이 :

        <asp:TextBox ID="Age" runat="server"></asp:TextBox><br />

        <br />

        <asp:Button ID="btnSubmit" runat="server" Text="전송" onclick="btnSubmit_Click" /><br />

       

    </div>

    </form>

</body>

</html>

 




 

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

 


==> [FrmRequest.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 FrmRequest : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        string strUserId = "";

        string strPassword = String.Empty;

        string strName = "";

        string strAge = String.Empty;

 

        //[1] Request 객체의 QueryString 컬렉션

        strUserId =

            Request.QueryString["UserID"];

 

        //[2] Request 객체의 Params 컬렉션

        strPassword =

            Request.Params["Password"];

 

        //[3] Request 객체의 Form 컬렉션

        strName = Request.Form["Name"];

 

        //[4] Request 객체 자체로 받기

        strAge = Request["Age"];

        string strMsg = String.Format(

            "입력하신 아이디는 {0}이고<br />"

            + "암호는 {1}입니다.<br />"

            + "이름은 {2}이고,<br />"

            + "나이는 {3}살 입니다.<br />",

            strUserId, strPassword,

            strName, strAge);

        Response.Write(strMsg);

    }

 

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

        // Empty

        // ASP.NET에서는 Request개체 보다는

        // 컨트롤의 속성을 사용해서 값을 받는다.

        string name = Name.Text; //

        int age = Convert.ToInt16(Age.Text); //

    }

}

 

 

 


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

 


[실행결과]

--> 아래그림에서 각 '텍스트 박스'에 입력한 데이터 중 "아이디"는 입력이 되지 않았다. 이것은 [FrmRequest.aspx.cs]코드의 strUserId = Request.QueryString["UserID"];부분에서 Request 객체의 QueryString 컬렉션으로 설정하였기 때문이다.(즉, "UserID"는 "QueryString"으로만 출력시킬 수 있다.)





--> 이번에는 '인터넷주소창'에 http://localhost:1148/WebASPNET/FrmRequest.aspx뒤에
 ?userID=a&Password=77&Name=aaa&Age=25QueryString입력하였는데 "이름"부분에는 입력한 QueryString이 출력되지 않은 것을 볼 수 있다. 이는 [FrmRequest.aspx.cs]코드의
strName = Request.Form["Name"];부분에서 Request 객체의 Form 컬렉션으로 설정하였기 때문이다.(즉, "Name"은 "폼(Form)"으로만 출력시킬 수 있다.)






Posted by holland14
: