Hi all,
I wrote the code below in client script block,
but I couldn't retrieve the cookie which was set in line 1.
Server1
processCookies.htm
url->http://Server1/mainSite/processCookies.aspx
------------------
document.cookie="myName=Test;domain=Server1";
alert(document.cookie);
------------------
My purpose is to share cookies between two or more web servers in my
LAN.
So if it works,I will change the domain value to Server2,
Server3...etc. in the main site processCookies page.
And then when users link to other site the cookie will also available.
Whether domain doesn't accept this kind format?
Thanks,
Albert
Michael Nemtsev - 11 Jul 2007 10:12 GMT
Hello alberthung01@gmail.com,
";" sign means the end of cookie value, so your server value is not stored,
AFAIK
I'd recommend to use the following codesnippet to store / extract cookies
/ primary function to retrieve cookie by name
function getCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) = = arg) {
return getCookieVal(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if (i = = 0) break;
}
return "";
}
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
> Hi all,
> I wrote the code below in client script block,
[quoted text clipped - 14 lines]
> Thanks,
> Albert
Alex Meleta - 11 Jul 2007 10:27 GMT
Hi,
Direct writing of semicolon to cookie's value is not possible by design (http://www.quirksmode.org/js/cookies.html),
as Michael mentioned before. But it's good practice to encode string before
writing there to solve similar issues (e.g. use base-64, see Convert.ToBase64String),
coz comma is not also possible.
Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
> Hi all,
> I wrote the code below in client script block,
[quoted text clipped - 14 lines]
> Thanks,
> Albert
alberthung01@gmail.com - 11 Jul 2007 15:49 GMT
Michael,Alex,
Thanks for your help and information!
Now I can set cookie successfully as long as I don't specify the
computer name as domain.
And I found the article describe which are invalid domain value.
http://www.ietf.org/rfc/rfc2109.txt
* The value for the Domain attribute contains no embedded dots or
does not start with a dot.
* The value for the request-host does not domain-match the Domain
attribute.
So the way I try to use to share cookies between diffenent web server
is impossible.
I'll try another way,thanks!