Request 개체 : 클라이언트에서 서버측에서 어떤 결과값을 요청


멤버

설명

QueryString[]

Get방식으로 넘겨져 쿼리스트링 값인 key value 받고자 사용한다.

Form[]

Pos방식으로 넘겨져 값을 key value 받고자 사용한다.

Params[]

사용자로부터 전송된 Get/Post 방식 모두를 받고자 사용한다.

UserHostAddress

현재 접속자의 IP주소 문자열을 반환해준다.

ServerVariables[]

현재 접속자의 주요 서버 환경 변수 값을 알려준다.

Cookies[]

저장된 쿠기 값을 읽어온다.

Url

현재 페이지의 URL 반환해준다.

PhysicalApplicationPath

현재 사이트의 가상 디렉터리의 물리적인 경로를 알려준다.

 


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

FrmRequestUserHostAddress  (0) 2009.10.05
FrmRequest  (0) 2009.10.05
FrmResponseRedirect  (0) 2009.10.05
FrmResponsebuffer  (0) 2009.10.05
FrmResponseWrite  (0) 2009.10.05
Posted by holland14
:

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



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

 

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

        <input type="button" value="이동" onclick="location.href='http://www.dotnetkorea.com';" /> <!-- JavaScript 방식 -->

   

        <asp:Button ID="btnDotNetKorea" runat="server" Text="닷넷코리아로 이동" onclick="btnDotNetKorea_Click" /> <!-- ASP.NET Response.Redirect 개체(클래스) 사용하는 방식 -->

    </div>

    </form>

</body>

</html>

 







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




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

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void btnDotNetKorea_Click(object sender, EventArgs e)

    {

        // 이동

        Response.Redirect("http://www.dotnetkorea.com/");

    }

}

 





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




[실행결과]
--> 웹페이지 첫화면




--> '이동' 또는 '닷넷 코리아로 이동'버튼을 누른 후 해당 URL로 넘어간 화면.





Posted by holland14
:

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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //[0] 현재 페이지를 매번 새로 읽어옴

        Response.Expires = -1; // -1이 기본값

 

        //[1] 버퍼링 사용 : 기본값

        Response.Buffer = true; // (IIS 7.0부터는) true가 기본값이다.

 

        //[2] 화면 글쓰기

        Response.Write(

            "[1] 현재 글은 보여짐<br />");

 

        //[3] 현재 버퍼에 있는 내용 출력

        Response.Flush();

 

        //[4] 화면 글쓰기

        Response.Write(

            "[2] 현재 글은 안 보임<br />");

 

        //[5] 현재 버퍼 내용 비우기

        Response.Clear();

 

        //[6] 문자열 출력

        Response.Write("[3] 보여짐<br />");

 

        //[7] 현재 페이지 종료

        Response.End(); // Response.Flush() + End()

 

        //[8] 문자열 출력

        Response.Write("[4] 실행 안 됨<br />");

    }

}

 




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



[실행결과]




Posted by holland14
:

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



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

 

<!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="btnClick" runat="server" Text="클릭" onclick="btnClick_Click" />

        <br />

       

        <%= "또 만나요...<br />" + DateTime.Now.ToShortDateString() + "<br />" %> <!-- <%="문자열" %>  : 기존의 ASP에서 많이 쓰던 기법이다. -->

       

        <asp:Button ID="btnJavaScript" runat="server" Text="자바스크립트로 인사말 출력"

            onclick="btnJavaScript_Click" />

        <br />

       

        <asp:Label ID="lblDisplay" runat="server" Text=""></asp:Label>

       

    </div>

    </form>

</body>

</html>

 







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




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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // 기존 ASP, ASP.NET MVC프레임워크에서 많이 쓰던 방법 : Response.Write(), <%= %>

        Response.Write("안녕하세요.<br />"); // 페이지 로드시 출력 / HTML레벨

 

        // ASP.NET 웹폼 레벨에서는 컨트롤을 주로 사용

        this.lblDisplay.Text = "안녕" + DateTime.Now.ToShortTimeString() + "<br />";

    }

 

 

    protected void btnClick_Click(object sender, EventArgs e)

    {

        Response.Write(

            "<span style='color:blue;'>반갑습니다.</span><br />"); // '클릭'버튼 클릭시 출력 / CSS레벨

    }

   

    protected void btnJavaScript_Click(object sender, EventArgs e)

    {

        string strJs = @"

            <script type='text/javascript'>

            window.alert('안녕');

            </script>

        ";

        Response.Write(strJs); // 자바스크립트를 실행하는 방법 중 하나

    }

}

 

 

 


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




[실행결과]




Posted by holland14
:
 

    ASP.NET 주요 내장 개체(클래스) : 클래식 ASP에서 사용하던 명령어와 동일

     

    Response 개체 : 서버 정보를 클라이언트에게 전송(응답)

    멤버

    설명

    Write

    페이지에 문자열을 출력한다.

    Redirect()

    지정된 페이지로 이동한다.

    Expires

    현재 페이지의 소멸 시간을 설정한다.

    Buffer

    버퍼링 사용 여부를 결정한다.

    Flush()

    현재 버퍼의 내용을 출력한다.

    Clear()

    현재 버퍼의 내용을 비운다.

    End()

    현재 페이지를 종료한다.

    WriteFile()

    스트림(파일) 출력한다.

    Cookies[]

    쿠키를 저장한다.

     

     

     


Posted by holland14
:

==> [App_Code]폴더에 "클래스 라이브러리"로 저장한 [Hi.cs]클래스파일소스



using System;

 

public class Hi

{

        public string Say()

        {

        return "안녕" + DateTime.Now.ToString();

        }

}

 

 

/*

여기서 만든 Hi.cs 클래스파일은 App_Code폴더에 저장이 되며,

웹애플리케이션에서 "공통"으로 사용할 수 있는 라이브러리 코드이다.

*/

 

 


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


* 웹폼으로 [FrmSay.aspx]파일과 코드 비하인드 페이지인 [FrmSay.aspx.cs]파일을 생성한다.(파일생성 후 [FrmSay.aspx]파일에서 "디자인" 및 "소스코딩"은 하지 않았다.)


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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Hi hi = new Hi();

        Response.Write(hi.Say() + "<br >"); // 현재 시간 출력

    }

}

 




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



[실행결과]

--> FrmSay.aspx(및 FrmSay.aspx.cs)파일에서 [App_Code]폴더에 "클래스 라이브러리"로 저장되어있는 [Hi.cs]클래스파일의 "Say()메서드"를 호출하여 사용하였다.





Posted by holland14
:

==> FrmVB.aspx.vb


 

Partial Class FrmVB

    Inherits System.Web.UI.Page

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

        '1부터 100까지 3의 배수 또는 4의 배수의 합

 

        '[1] Input

        Dim sum As Integer = 0

 

        '[2] Process

 

        For i As Integer = 1 To 100 Step 1

 

 

            If i Mod 3 = 0 Or i Mod 4 = 0 Then

                sum = sum + i

            End If

 

        Next

 

        '[3] Output

        Response.Write("1~100까지 배수의 합 : " & sum.ToString())

 

    End Sub

End Class

 


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



[실행결과]





Posted by holland14
:

==> FrmHello.aspx 소스 및 디자인


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

 

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

   

        UI / 디자인 : aspx에서</div>

    </form>

</body>

</html>

 








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




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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // 기능은 aspx.cs에서, , 코드비하인드 페이지에서...

        Response.Write("반갑습니다...");

    }

}

 



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



[실행결과]

Posted by holland14
:

==> FrmHi.aspx



<%@ Page Language="C#" %>

 

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

 

<script runat="server">

 

    protected void Page_Load(object sender, EventArgs e)

    {

        Response.Write("안녕하세요...");

    }

</script>

 

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

<head runat="server">

    <title></title>

</head>

<body>

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

    <div>

   

    </div>

    </form>

</body>

</html>

 




[실행결과]




Posted by holland14
:


==> Default.aspx

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

 

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

    <style type="text/css"">

    .myBackGround { background-color:Yellow; }

    </style>

    <script type="text/javascript">

        function Hi() {

            alert("안녕하세요.");

        }

    </script>

</head>

<body>

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

    <div>

        HTML 레벨 : <a href="http://www.dotnetkorea.com/">닷넷코리아</a><br />

        CSS 레벨 : <span class="myBackGround">스타일시트가 적용됨</span><br />

        JavaScript 레벨 : <input type="button" value="클릭" onclick="Hi()" /><br />

        ASP.NET 레벨 : <asp:Calendar ID="myCalendar" runat="server"></asp:Calendar><br />

    </div>

    </form>

</body>

</html>




[실행결과]







Posted by holland14
: