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
:
 

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
: