Cookie.Version 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
쿠키가 준수하는 HTTP 상태 유지 관리 버전을 가져오거나 설정합니다.
public:
property int Version { int get(); void set(int value); };
public int Version { get; set; }
member this.Version : int with get, set
Public Property Version As Integer
속성 값
쿠키가 준수하는 HTTP 상태 유지 관리 버전입니다.
예외
버전에 지정된 값이 허용되지 않는 경우
예제
다음 예제에서는 응답에 반환된 쿠키의 속성을 표시합니다. 전체 예제는 클래스 항목을 참조 Cookie 하세요.
var request = (HttpWebRequest)WebRequest.Create(args[0]);
request.CookieContainer = new CookieContainer();
using (var response = (HttpWebResponse) request.GetResponse())
{
// Print the properties of each cookie.
foreach (Cookie cook in response.Cookies)
{
Console.WriteLine("Cookie:");
Console.WriteLine($"{cook.Name} = {cook.Value}");
Console.WriteLine($"Domain: {cook.Domain}");
Console.WriteLine($"Path: {cook.Path}");
Console.WriteLine($"Port: {cook.Port}");
Console.WriteLine($"Secure: {cook.Secure}");
Console.WriteLine($"When issued: {cook.TimeStamp}");
Console.WriteLine($"Expires: {cook.Expires} (expired? {cook.Expired})");
Console.WriteLine($"Don't save: {cook.Discard}");
Console.WriteLine($"Comment: {cook.Comment}");
Console.WriteLine($"Uri for comments: {cook.CommentUri}");
Console.WriteLine($"Version: RFC {(cook.Version == 1 ? 2109 : 2965)}");
// Show the string representation of the cookie.
Console.WriteLine($"String: {cook}");
}
}
Dim request As HttpWebRequest = WebRequest.Create(args(0))
request.CookieContainer = New CookieContainer()
Using response As HttpWebResponse = request.GetResponse()
' Print the properties of each cookie.
For Each cook As Cookie In response.Cookies
Console.WriteLine("Cookie:")
Console.WriteLine($"{cook.Name} = {cook.Value}")
Console.WriteLine($"Domain: {cook.Domain}")
Console.WriteLine($"Path: {cook.Path}")
Console.WriteLine($"Port: {cook.Port}")
Console.WriteLine($"Secure: {cook.Secure}")
Console.WriteLine($"When issued: {cook.TimeStamp}")
Console.WriteLine($"Expires: {cook.Expires} (expired? {cook.Expired})")
Console.WriteLine($"Don't save: {cook.Discard}")
Console.WriteLine($"Comment: {cook.Comment}")
Console.WriteLine($"Uri for comments: {cook.CommentUri}")
Console.WriteLine($"Version: RFC {If(cook.Version = 1, 2109, 2965)}")
' Show the string representation of the cookie.
Console.WriteLine($"String: {cook}")
Next
End Using
설명
속성의 Version 기본값은 원래 Netscape 사양을 준수하는 0입니다. 값이 명시적으로 1 Cookie 로 설정된 경우 RFC 2109를 준수해야 합니다. Set-Cookie2 HTTP 응답 헤더를 수신하여 가 자동으로 만들어진 경우 Cookie 준수는 RFC 2965로 설정됩니다.
속성을 0보다 작은 값으로 설정 Version 하면 예외가 throw됩니다.