HttpRequest.Cookies 속성

정의

클라이언트에서 보낸 쿠키 컬렉션을 가져옵니다.

public:
 property System::Web::HttpCookieCollection ^ Cookies { System::Web::HttpCookieCollection ^ get(); };
public System.Web.HttpCookieCollection Cookies { get; }
member this.Cookies : System.Web.HttpCookieCollection
Public ReadOnly Property Cookies As HttpCookieCollection

속성 값

HttpCookieCollection

클라이언트의 쿠키 변수를 나타내는 HttpCookieCollection 개체입니다.

예제

다음 코드 예제에서는 클라이언트에서 보낸 모든 쿠키를 반복하고 각 쿠키의 이름, 만료 날짜, 보안 매개 변수 및 값을 HTTP 출력으로 보냅니다.

int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;

MyCookieColl = Request.Cookies;

// Capture all cookie names into a string array.
String[] arr1 = MyCookieColl.AllKeys;

// Grab individual cookie objects by cookie name.
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
   MyCookie = MyCookieColl[arr1[loop1]];
   Response.Write("Cookie: " + MyCookie.Name + "<br>");
   Response.Write ("Secure:" + MyCookie.Secure + "<br>");

   //Grab all values for single cookie into an object array.
   String[] arr2 = MyCookie.Values.AllKeys;

   //Loop through cookie Value collection and print all values.
   for (loop2 = 0; loop2 < arr2.Length; loop2++)
   {
      Response.Write("Value" + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
   }
}

Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim MyCookieColl As HttpCookieCollection 
Dim MyCookie As HttpCookie

MyCookieColl = Request.Cookies
' Capture all cookie names into a string array.
arr1 = MyCookieColl.AllKeys
' Grab individual cookie objects by cookie name     
for loop1 = 0 To arr1.GetUpperBound(0)
   MyCookie = MyCookieColl(arr1(loop1))
   Response.Write("Cookie: " & MyCookie.Name & "<br>")
           Response.Write("Secure:" & MyCookie.Secure & "<br>")

   ' Grab all values for single cookie into an object array.
   arr2 = MyCookie.Values.AllKeys
   ' Loop through cookie value collection and print all values.
   for loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) + ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1
  

설명

ASP.NET 두 내장 쿠키 컬렉션을 포함합니다. 클라이언트가 헤더의 Cookies HttpRequest 서버로 전송하는 쿠키를 포함하는 컬렉션을 통해 액세스하는 Cookie 컬렉션입니다. 컬렉션의 컬렉션을 통해 Cookies 액세스되는 컬렉션 HttpResponse 에는 서버에서 만들어지고 헤더의 클라이언트로 전송되는 새 쿠키가 Set-Cookie 포함되어 있습니다.

참고

컬렉션을 사용하여 HttpResponse.Cookies 쿠키를 추가한 후에는 응답이 클라이언트로 전송되지 않은 경우에도 컬렉션에서 HttpRequest.Cookies 쿠키를 즉시 사용할 수 있습니다.

적용 대상

추가 정보