HttpRequest.Cookies HttpRequest.Cookies HttpRequest.Cookies HttpRequest.Cookies Property

정의

클라이언트에서 보낸 쿠키 컬렉션을 가져옵니다.Gets a collection of cookies sent by the client.

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 개체입니다.An HttpCookieCollection object representing the client's cookie variables.

예제

다음 코드 예제에서는 클라이언트에서 보낸 모든 쿠키를 통해 반복 하 고 이름, 만료일, 보안 매개 변수 및 각 쿠키의 값을 HTTP 출력에 보냅니다.The following code example loops through all cookies sent by the client and sends the name, expiration date, security parameter, and values of each cookie to the HTTP output.

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 두 내장 쿠키 컬렉션을 포함합니다.ASP.NET includes two intrinsic cookie collections. 통해 액세스할 수 있는 컬렉션을 Cookies 의 컬렉션 HttpRequest 서버에 클라이언트에서 전송 된 쿠키가 들어를 Cookie 헤더.The collection accessed through the Cookies collection of HttpRequest contains cookies transmitted by the client to the server in the Cookie header. 통해 액세스할 수 있는 컬렉션을 Cookies 의 컬렉션 HttpResponse 서버에서 생성 하 고 클라이언트에 전송 된 새 쿠키를 포함는 Set-Cookie 헤더입니다.The collection accessed through the Cookies collection of HttpResponse contains new cookies created on the server and transmitted to the client in the Set-Cookie header.

참고

사용 하 여 쿠키를 추가한 후는 HttpResponse.Cookies 쿠키에서 즉시 사용할 수는 컬렉션을 HttpRequest.Cookies 응답이 클라이언트로 전송 되지 않은 경우에 컬렉션.After you add a cookie by using the HttpResponse.Cookies collection, the cookie is immediately available in the HttpRequest.Cookies collection, even if the response has not been sent to the client.

적용 대상

추가 정보