본문 바로가기
프로그래밍 언어/C#

[ASP.NET][C#] Request 개체

by Nataliaa 2023. 2. 17.

Request Object

Request 개체는 GET 또는 POST에서 전송된 데이터를 받고자 할 때 가장 많이 사용한다.  Request 개체는 사용자로부터 정보를 전달 받을 때 주로 사용되는 개체이다. 

 

 


Request.Form

POST 폼 요청으로 전송된 모든 HTML 컨트롤 요소 값 

protected void Page_Load(object sender, EventArgs e)
{
    string strUserName = "";

    // Request 객체의 Form 컬렉션
    strUserName = Request.Form["userName"];

}

 

 

Request.QueryString

사용자 요청에서 URL에 추가된 모든 이름/값이나 GET 방식이 사용된 폼에 있는 HTML 컨트롤 요소 값

protected void Page_Load(object sender, EventArgs e)
{
    string strUserID = "";

    // Request 객체의 QueryString 컬렉션
    strUserID = Request.QueryString["userID"];

}

 

 

Request.Params

GET/POST 상관없이 Request.Params["name"] 이나 Request["name"]으로 받을 수도 있다.

protected void Page_Load(object sender, EventArgs e)
{
    string strUserID = "";
    string strUserAge = String.Empty;

    // Request 객체의 Params 컬렉션
    strUserID = Request.Params["userID"];
    
    // Request 객체 
    strUserPW = Request["userPW"];

}

 


 

Request.Cookies

사용자의 시스템에서 요청과 함께 전달된 모든 쿠키값

protected void Page_Load(object sender, EventArgs e)
{

	//현재 시간을 쿠키에 저장
	Response.Cookies["NOW"].Value = DateTime.Now.ToShortTimeString();
	
	//쿠키 읽어오기
	string now = Request.Cookies["NOW"].Value;

}

 

 

Request.ServerVariables

클라이언트로부터 이들의 요청과 함께 전달된 모든 HTTP 헤더 값들과 웹 서버의 여러가지 환경 변수값 

 

 

 

 

 


 

 

 

'프로그래밍 언어 > C#' 카테고리의 다른 글

구글 api 사용하여 SNS 로그인 연동  (0) 2023.09.20
[ASP.NET][C#] Response 개체  (0) 2023.02.17
[ASP.NET][C#] Web Forms 이벤트 처리  (0) 2023.02.16
[ASP.NET][C#] postback 포스트백  (0) 2023.02.16
[C#] 기본 구조  (0) 2022.11.06

댓글