The definition you gave is correct, you do specify a time that the cookie
will expires on the client. You just don't set it absolutely that's all.
30 days from today produces a time just as well as 12/31/05 does.
The code I gave you comes directly from the MSDN help on the Expires
property of the HttpCookie class.
Sliding expirations have always been the way cookies have worked. Imagine
setting an absolute date/time and having a new user come to the page 5
seconds before that time!
Scott,
I'm still curious who's right: you or MS documentation
The
documentation for HttpCookie.Expires Property says "The time of day (on the
client) at which the cookie expires." - sounds like an absolute value...
On other hand maybe some lower .NET level translates this absolute value
to time span (but still it should know the local time) or the browser does
the translation ? Or maybe according to the cookie standard this value is
always relative ?
Oleg
:
If you intend to read/write cookies from the server-side, then this is
the
price you pay. You certainly can do it client-side or capture the local
time client-side and send it to the server as a hidden form field.
Either
way, cookie expirations are not set absolutely, they are set based on a
timespan.
Thanks Scott, I'm familiar with the syntax, but suppose that your
server
runs at US and the client at Siberia, so when the cookie will reach the
recipient his browser will simply discard it.
Oleg
:
Here you go Oleg:
Example
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)
message
Actually my application involves Java Applet tah's embedded at one
of
ASPXs, so it could supply the local time... But I'm still wondering
how
other people handle this issue without java script.
Oleg
:
Yes,
If you're able to get a value back from the client you could
trust
that
you
would know exactly when the cookie would expire.
Of course this solution counts on the client having javascript
enabled.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
message
Justin,
do u mean that cookie expiration time is an absolute value ?
Oleg
:
Oleg,
You could use a javascript to enter the client's time into a
hidden
form
field.
Of course this information would then have to be posted back
before
setting
the cookie...
Something like this:
<script language="Javascript">
<!--
document.Form1.myHiddenField.value = new Date()
//-->
</script>
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
in
message
Hi,
(newbie question)
I've created some simple .NET ASP application that should
store
cookies at
the client machine.
According to the documentation cookie expiration time is
set
via
HttpCookie.Expires property, but property value is the time
of
day
on
the
client.
How can I possibly know client local time ?
Thanks in advance !!!