When calling Response.Cookie.Add(new HttpCookie("MyCookie", "objValue")); where does the cookie saved? on Client Machine or Server Machine?
EDIT:
if saved in Client Machine, how can I read it from javascript then? I tried this kind of script.
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
I cannot get the cookie that I saved from code behind. When I look into the document.cookie object, it is just an empty string.
Scenario:
- On Page_Init() on code behind. I create a cookie using
Response.Cookie.Add(new HttpCookie("MyCookie", "cookieValue"));. - On Client side, I’m trying to read the cookie saved from code behind on page load using the snippet above, but it returns
undefined
As Wikipedia explains, cookies string values that are stored on the client.
They are sent to server with each HTTP request as
Cookie:headers.You can store arbitrary objects in the server using session state.