This documentation is archived and is not being maintained.

HttpCookie.Expires Property

Gets or sets the expiration date and time for the cookie.

[Visual Basic]
Public Property Expires As DateTime
public DateTime Expires {get; set;}
public: __property DateTime get_Expires();
public: __property void set_Expires(DateTime);
public function get Expires() : DateTime;
public function set Expires(DateTime);

Property Value

The time of day (on the client) at which the cookie expires.


The following example sets the expiration time of the cookie to 10 minutes from the current time.

[Visual Basic] 
Dim dt As DateTime = DateTime.Now()
 Dim ts As New TimeSpan(0,0,10,0)
 MyCookie.Expires = dt.Add(ts)

DateTime dt = DateTime.Now;
 TimeSpan ts = new TimeSpan(0,0,10,0);
 MyCookie.Expires = dt.Add(ts);

DateTime dt = DateTime::Now;
 TimeSpan ts = TimeSpan(0,0,10,0);
 MyCookie->Expires = dt.Add(ts);

var dt : DateTime = DateTime.Now
var ts : TimeSpan = new TimeSpan(0,0,10,0)

myCookie.Expires = dt.Add(ts)


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpCookie Class | HttpCookie Members | System.Web Namespace