
using same cookie server-side and client-side
There is no such thing as a server-side cookie. Cookies are always stored on the
client. They can be *written* or *read* on the server, but they still reside on
the client. Any cookie that can be read by the server can also be read on the
client side.
That said, you can certainly read/write them on the client side if you know how.
Here's the MS reference:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/...
And here are some functions that you can use to read and write cookies with keys
(the kind you call "multiple value" MS calls "with keys") on the client side.
Note that the addToCookie() function uses a 1-year expiration term. You can make
it whatever you want.
Use getCookie("cookie1","crumb1") for reading the cookie in your example.
Use addToCookie("cookie1","crumb1","cookie-value") to simulate what you did on
the server side
function parseCookie(name) {
var str = ""
var a = document.cookie.split(";")
for (var i=0; i<a.length; i++) {
a[i] = a[i].trim()
if (a[i].substring(0,name.length) == name)
str = a[i].substring(name.length+1)
}
var a = str.split("&")
var obj = new Object()
if (str.length)
for (i=0; i<a.length; i++) {
temp = a[i].split("=")
obj[temp[0]] = temp[1]
}
return obj
Quote:
}
function addToCookie(cookieName,key,value) {
var cookies = parseCookie(cookieName)
cookies[key] = value
var d = new Date()
d.setFullYear(d.getFullYear()+1)
var cookieStr = cookieName + "="
for (var item in cookies)
cookieStr += item + "=" + cookies[item] + "&"
cookieStr = cookieStr.substring(0,cookieStr.length-1)
cookieStr = cookieStr + "; expires=" + d.toUTCString()
cookieStr = cookieStr + "; path=/"
document.cookie = cookieStr
Quote:
}
function getCookie(name,key) {
var cookies = parseCookie(name)
return cookies[key]
Quote:
}
> I am trying to use the same cookies on the server-side and the
> client-side. I am creating a multiple-value cookie on the server side
> using
> response.cookies("cookie1")("crumb1") = "cookie-value"
> and I would like to read that cookie and update it through client-side
> code such as
> a = document.cookie
> document.cookie = "crumb2=" & cookie-value2
> I can't seem to figure out how the server names the cookie and how I
> can read it in on the client. When I create one on the client, it
> does not appear to have a name.
> Basically I am just not sure if this can be done at all.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use of
this email address implies consent to these terms. Please do not contact me
directly or ask me to contact you directly for assistance. If your question is
worth asking, it's worth posting.