Cookie.Version Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает версию обслуживания состояния HTTP, для которой соответствует файл cookie.
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.
Исключения
Значение, указанное для версии, запрещено.
Примеры
В следующем примере отображаются свойства файлов cookie, возвращаемых в ответе. Полный пример см. в 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 свойства равно 0, соответствует исходной спецификации Netscape. Если для значения явно задано значение 1, это Cookie должно соответствовать RFC 2109. Обратите внимание, что при Cookie автоматическом получении заголовка ответа HTTP Set-Cookie2 соответствие имеет значение RFC 2965.
Попытка задать Version для свойства значение меньше нуля приведет к возникновению исключения.