* 컴포넌트 레벨에서 출력할 때 쓰인다.


* 클래스라이브러리나 애플리케이션 라이브러리에서 사용할 때 쓴다.

 "WebHttpContext"프로젝트(파일)에 App_Code폴더를 만들어서 Msg.cs 클래스 파일을 생성한 후 HttpContext 클래스를 사용하는 코드를 작성한다.





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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //[0] 추적 설정

        Trace.IsEnabled = true;

 

        // 화면 출력

        //[1] Page 레벨에서 출력

        Response.Write("안녕<br />");

 

        //[2] Component 레벨 : 클래스(App_Code, *.DLL)레벨

        HttpContext.Current.Response.Write("방가<br />");

        HttpContext context = HttpContext.Current;

        context.Response.Write("또 봐<br />");

 

        //[3] 호출

        Msg.Show();

    }

}

 


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



[App_Code/Msg.cs] 소스 코드


using System;

using System.Web;

 

public class Msg

{

    public static void Show()

    {

        // Response.Write(), Response.Cookies[]

        HttpContext.Current.Response.Write("컴포넌트 레벨에서 출력<br />");

        HttpContext context = HttpContext.Current;

        context.Response.Cookies["A"].Value = "A";

        context.Response.Cookies["B"].Value = "B";

    }

}

 

 


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



[실행결과]





Posted by holland14
: