This function returns a properly formatted cookie string given the parameters supplied to the function. The cookie string can then be appended to the head section of an HTML page being generated for the browser to take the appropriate cookie action. The string is created as a META set-cookie tag.
Parameter: name
Type: string
Description: This is the name of the
cookie. If
commas, whitespace, semi-colons or other non-HTML friendly characters
are used, then it should be noted that the name string is URL encoded
in the returned string, so the name used to retrieve the cookie may have
to be updated to use the URL encoded version.
Parameter:
value
Type: string
Description: This is the value of the
cookie. If
commas, whitespace, semi-colons or other non-HTML friendly characters
are used, then it should be noted that the value string is URL encoded
in the returned string, so the value returned when you read the cookie
back may have to be URL decoded.
(See System.Web.HTTPServerUtility.URLDecode)
Parameter: expire
(optional)
Type: string
Description: This is the expiration
date and time for the cookie. If
this parameter is omitted, then no expiration will be provided and the
cookie will be erased when the web browser session ends. The
date can be in any string format which can be converted by DateTime.Parse
such as "April 1, 2006 11:27 PM". You
may also use your system's local date/time format converted to a string
value. The
date provided is converted to GMT for purposes of formatting according
to RFCs 822, 850, 1036 and 1123.
Parameter: path
(optional)
Type: string
Description: This is the path that
the cookie is valid for under the server host. If
a cookie has already passed domain matching, then the pathname component
of the URL is compared with the path attribute, and if there is a match,
the cookie is considered valid and is sent along with the URL request.
The path "/foo" would match "/foobar" and "/foo/bar.html".
The path "/" is the most general path and is the default value
if this parameter is omitted.
Return value: cookie
contents
Type: string
Description: This is the contents of
the requested cookie.
This script:
Sub Main(parm as object)
Dim
sCookie As String = ""
sCookie
= hs.GenCookieString("Test", "MyValue", Now.AddDays(10).ToString,
"/")
hs.WriteLog("Cookie",
sCookie)
End Sub
Generates this result:
9/21/2006 7:01:50 PM - Cookie - <meta http-equiv="Set-Cookie" content="Test=MyValue; expires=Sun, 01-Oct-2006 23:01:50 GMT; path=/;">