6

Response.Cookies["alertsCookie"]给了我一块空白饼干。

我制作了两个 cookie,因为我不知道如何在路径中读取 cookie,所以我决定将它们写入两个位置(页面路径和 /)

代码隐藏:

HttpCookie seenAlertsCookie = Response.Cookies["alertsCookie"];

JavaScript (jQuery):

var cookie = $.cookie("alertsCookie");
alert(cookie);
if (cookie == null) {
    $.cookie('alertsCookie', alertGuid, { expires: 7300, path: '/' });
    $.cookie('alertsCookie', alertGuid, 7300);

}
else {
    var cookieVal = cookie + '|';
    cookieVal = cookieVal + alertGuid;
    $.cookie('alertsCookie', cookieVal, { expires: 7300, path: '/' });
    $.cookie('alertsCookie', cookieVal, 7300);
}
4

1 回答 1

15

查看Request而不是Response.

HttpCookie seenAlertsCookie = Request.Cookies["alertsCookie"];

Response.Cookies用于在浏览器上设置 cookie,Request.Cookies用于读取来自浏览器的 cookie。

于 2012-10-19T20:04:17.077 回答