ASP.NET

53.C# ASP.NET - HttpContext [상태관리1]

Godffs 2009. 10. 20. 21:40
반응형
개별 HTTP 요청에 대한 HTTP 관련 정보를 모두 캡슐화
- HTTPContext.Current 속성 : 현재 HTTP 요청에 대한 HTTPContext 객체를 가져오거나 설정

새 항목 추가 - Web From ( FrmHttpContext.aspx )
바로 코드 비하인드 페이지로 이동
FrmHttpContext.aspx.cs

protected void Page_Load(object sender, EventArgs e)

{

    // 화면 출력

    //[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 폴더 추가 후 Class 추가 ( Msg.cs )
Msg.cs

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";

        }

} // 클래스 레벨로 HttpContext 통해서 요청해라


결과화면

[그림53-1]


반응형