Cookie.Name Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает имя для Cookieобъекта .
public:
property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String
Значение свойства
Имя для Cookie.
Исключения
Значение, указанное для операции набора, или null пустая строка
–или–
Значение, указанное для операции набора, содержало недопустимый символ. Следующие символы не должны использоваться внутри Name свойства: знак равенства, запятая, запятая, newline (\n), return (\r), tab (\t) и пробел. Символ знака доллара ("$") не может быть первым символом.
Примеры
В следующем примере отображаются свойства файлов 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
Комментарии
Свойство Name необходимо инициализировать перед использованием экземпляра Cookie класса.
Следующие символы зарезервированы и не могут использоваться для этого значения атрибута: знак равенства, точка с запятой, запятая, новая строка (\n), возвращаемая (\r), вкладка (\t) и пробел. Знак доллара ($) не может быть первым символом.