开发者

ASP.NET Response.Cookie client or server?

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:

  1. On Page_Init() on code behind. I create a cookie using Response.Coo开发者_运维知识库kie.Add(new HttpCookie("MyCookie", "cookieValue"));.
  2. 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.


Client machine. I'm sure google could give you a good explanation, But I use it everyday, and experience is my source.


Cookies are always saved at Client Machine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜