Well I do have sample code from CodeProject that is working. I
changed that code to look like the way I am expiring and it works
there.. the cookie really only does last 10 minutes, as I specify in
the code. Although the last time I tried this test was at 2PM ;-)
Here is the sample from CodeProject:
************************************************** *****************************
<%@ Language=VBScript %>
<%
Option Explicit
On Error Resume Next
' test if the client browser support cookies
dim objBrowserCapabilities
dim blnSupportCookies
set objBrowserCapabilities =
server.CreateObject("MSWC.BrowserType")
if Err.number <> 0 then
Response.Write "Error: Can't create MSWC.BrowserType
object."
Response.End
end if
' get the cookies boolean value
blnSupportCookies = objBrowserCapabilities.cookies
if UCase(blnSupportCookies) <> "TRUE" then
blnSupportCookies = false
end if
set objBrowserCapabilities = nothing
' global declaration
dim index
dim indexKey
' verify if the user wants write a cookie dictionary
dim strWriteCookieDictionary
dim blnWriteCookieDictionary
blnWriteCookieDictionary = false
strWriteCookieDictionary = request("WriteCookieDictionary")
if strWriteCookieDictionary <> "" then
dim intKeysNumber
intKeysNumber = request("NumberOfKeys")
' test if intKeysNumber is a valid number
if intKeysNumber < 0 or not IsNumeric(intKeysNumber)
then
Response.Write "Error: You provided an invalid
value for keys number! (must be integer > 0)"
Response.End
else
blnWriteCookieDictionary = true
Session("sintKeysNumber") = intKeysNumber
end if
end if ' strWriteCookieDictionary <> ""
' verify if the user submited the page
dim strSubmit
strSubmit = request("Submit")
if strSubmit <> "" then
' declare used variables
dim strCookieName
dim strCookieValue
dim astrCookieKeyName()
dim astrCookieKeyValue()
dim strCookieExpires
dim strCookieExpiresDate
dim strCookieExpiresHour
' read the objects values from request
strCookieName = request("CookieName")
strCookieValue = request("CookieValue")
strCookieExpires = request("CookieExpires")
strCookieExpiresDate = request("CookieExpiresDate")
strCookieExpiresHour = request("CookieExpiresHour")
' if CookieValue is empty is possible user write a
dictionary
' looping the form collection to search Key names and
values
if strCookieValue = "" then
dim intKeysCount
intKeysCount = 0
for each index in Request.Form
if Left(index,4) = "KeyN" then
intKeysCount = intKeysCount +
1
redim preserve
astrCookieKeyName(intKeysCount)
redim preserve
astrCookieKeyValue(intKeysCount)
astrCookieKeyName(intKeysCount
- 1) = request("KeyName_" & intKeysCount)
astrCookieKeyValue(intKeysCount - 1) = request("KeyValue_" &
intKeysCount)
end if
next
end if
' if CookieName isn't empty then save the cookie
if Trim(strCookieName) <> "" then
' write the cookies to client browser
if intKeysCount = 0 then
Response.Cookies(strCookieName) =
strCookieValue
else
for index = 0 to intKeysCount - 1
Response.Cookies(strCookieName)(astrCookieKeyName( index)) =
astrCookieKeyValue(index)
next
end if
' test if the cookie has a expiration date and
set it
if strCookieExpires = "FALSE" then
'Response.Cookies(strCookieName).expires = strCookieExpiresDate & " "
& strCookieExpiresHour
'*****************
'my change is here
'*****************
Response.Cookies(strCookieName).expires = DateAdd("n", 10, Now())
end if
end if
end if ' strSubmit <> ""
%>
<html>
<head>
<script language="JavaScript">
<!--
//'************************************************* ********************************
//' Description: Set the disabled property to edit objects
//' Assumptions: None
//' Effects: Disabling or enabling edit objects
//' Arguments: {p_strOption] - string value
//' Returns: None
//' Version: [01/31/2000 - Iulian Iuga]
//'************************************************* ********************************
function ShowHide(p_strOption)
{
if (p_strOption == 'TRUE')
{
document.WriteCookies.CookieExpiresDate.disabled =
true
document.WriteCookies.CookieExpiresHour.disabled =
true
}
else
{
document.WriteCookies.CookieExpiresDate.disabled =
false
document.WriteCookies.CookieExpiresHour.disabled =
false
}
}
//-->
</script>
</head>
<body>
<center><h2>Read and write cookies to your browser</h2></center>
<hr>
<br>
<% if not blnSupportCookies then
Response.Write "<b>Your browser doesn't support
cookies!</b>"
else
%>
<h3>Read Cookies:</h3>
<%
' looping trough cookies collection
for each index in Request.Cookies
' test if cookie is dictionary
if Request.Cookies(index).HasKeys then
Response.Write "
<b>Cookie</b> <i>" & index & "</i> <b>is dictionary</b>"
Response.Write
" Count = " & Request.Cookies(index).Count &
"<br>"
for each indexKey in
Request.Cookies(index)
Response.Write
" <b>Key</b> <i>" & indexKey & "</i> = <i>" &
Request.Cookies(index)(indexKey) & "</i><br>"
next
else
Response.Write "
<b>Cookie</b> <i>" & index & "</i> = <i>" & Request.Cookies(index) &
"</i><br>"
end if
next
%>
<hr>
<br>
<h3>Write Cookies:</h3>
<form name="WriteCookies" action="default.asp" method="POST">
<input type="Submit" name="WriteCookieDictionary"
value="Write cookie dictionary"> <b>with</b>
<input type="text" name="NumberOfKeys" value="0" size="3"
maxlength="3"> <b>keys.</b>
<br><br>
<table border="0">
<tr><td>Cookie Name: </td>
<td><input type="text" name="CookieName"
value="" size="20"></td></tr>
<% if not blnWriteCookieDictionary or
intKeysNumber = 0 then %>
<tr><td>Cookie Value: </td>
<td><input type="text" name="CookieValue"
value="" size="20"></td></tr>
<% else
for index = 1 to intKeysNumber
Response.Write
"<tr><td> Key_" & index & " Name: </td>"
Response.Write "<td><input
type='text' name='KeyName_" & index & "' value=''
size='15'></td></tr>"
Response.Write
"<tr><td> Key_" & index & " Value: </td>"
Response.Write "<td><input
type='text' name='KeyValue_" & index & "' value=''
size='15'></td></tr>"
next
end if
%>
</table><br>
<input type="radio" name="CookieExpires" value="TRUE"
onclick="ShowHide('TRUE')" checked> Expires after shut down this
session<br>
<input type="radio" name="CookieExpires" value="FALSE"
onclick="ShowHide('FALSE')"> Don't expires (populate Date and
Hour)<br>
<table border="0">
<tr><td>Date: </td>
<td><input type="text"
name="CookieExpiresDate" value="<%=Date%>" size="10"
disabled>(Month/Day/Year - i.e. 2/1/2000)</td></tr>
<tr><td>Hour: </td>
<td><input type="text"
name="CookieExpiresHour" value="<%=Time%>" size="10"
disabled>(Hour/Minutes/Seconds - i.e. 2:30:25 PM)</td></tr>
</table>
<br>
<hr>
<input type="Submit" name="Submit"
value="Submit">
<button name="Help" value="Help" alt="Help"
onclick="window.showModalDialog('help.asp')">Help</button>
</form>
<% end if %>
</body>
</html>
************************************************** ******************************
On Wed, 10 Sep 2003 10:21:47 -0400, "Ray at <%=sLocation%>"
<myfirstname at lane34 dot com> wrote:
Maybe your cookie issues have to do with your expiration methods. IIRC, you
cannot specify that a cookie expires at a certain hour. You can only
specify the calendar date. You're expiring your cookies by adding hours to
the current time, so if you wind up being on the same calendar date after
adding the hours, your cookie would expire today. Maybe your code will work
in the evening. :]
Ray at work
"Brian Burgess" <bb********@hotmail.com> wrote in message
news:q8********************************@4ax.com.. . to go on..
But since it never writes the cookie .. the process as outlined doesnt
work.. :-(
On Wed, 10 Sep 2003 12:48:46 GMT, ji***@online.microsoft.com (Jacob
Yang [MSFT]) wrote:
>Hi Brian,
>
>There should be a server-client round-trip between the code to create a
>cookie and the code to retrieve the same cookie.
>
>The cookie is available only in the subsequent requests to the webserver. >
>Best regards,
>
>Jacob Yang
>Microsoft Online Partner Support
><MCSD>
>Get Secure! ¨C www.microsoft.com/security
>This posting is provided "as is" with no warranties and confers no
rights.