Cookie. Expires Property

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets or sets the expiration date and time for the Cookie as a DateTime.

public: property DateTime Expires < DateTime get(); void set(DateTime value); >;
public DateTime Expires
member this.Expires : DateTime with get, set
Public Property Expires As DateTime

Property Value

The expiration date and time for the Cookie as a DateTime instance.

Examples

The following example displays the properties of cookies returned in a response. For the complete example, see the Cookie class topic.

HttpWebRequest^ request = dynamic_cast(WebRequest::Create( args[ 1 ] )); request->CookieContainer = gcnew CookieContainer; HttpWebResponse^ response = dynamic_cast(request->GetResponse()); response->Cookies = request->CookieContainer->GetCookies( request->RequestUri ); // Print the properties of each cookie. System::Collections::IEnumerator^ myEnum = response->Cookies->GetEnumerator(); while ( myEnum->MoveNext() ) < Cookie^ cook = safe_cast(myEnum->Current); 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: (expired? )", cook->Expires, 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 ? (String^)"2109" : "2965" ); // Show the string representation of the cookie. Console::WriteLine( "String: ", cook ); > 
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($"= "); Console.WriteLine($"Domain: "); Console.WriteLine($"Path: "); Console.WriteLine($"Port: "); Console.WriteLine($"Secure: "); Console.WriteLine($"When issued: "); Console.WriteLine($"Expires: (expired? )"); Console.WriteLine($"Don't save: "); Console.WriteLine($"Comment: "); Console.WriteLine($"Uri for comments: "); Console.WriteLine($"Version: RFC <(cook.Version == 1 ? 2109 : 2965)>"); // Show the string representation of the cookie. Console.WriteLine($"String: "); > > 
 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($" = ") Console.WriteLine($"Domain: ") Console.WriteLine($"Path: ") Console.WriteLine($"Port: ") Console.WriteLine($"Secure: ") Console.WriteLine($"When issued: ") Console.WriteLine($"Expires: (expired? )") Console.WriteLine($"Don't save: ") Console.WriteLine($"Comment: ") Console.WriteLine($"Uri for comments: ") Console.WriteLine($"Version: RFC ") ' Show the string representation of the cookie. Console.WriteLine($"String: ") Next End Using 

Remarks

Setting the Expires property to DateTime.MinValue makes this a session cookie, which is its default value.

The Kind property of Expires is used to determine if the cookie is set to DateTimeKind.Local or DateTimeKind.Utc. If the Kind property is set to DateTimeKind.Unspecified, then Utc is assumed.