Response.Cookies["alertsCookie"]给了我一个空白的cookie。

我已经制作了两个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);
}

最佳答案

查看Request而不是Response

HttpCookie seenAlertsCookie = Request.Cookies["alertsCookie"];
Response.Cookies用于在浏览器上设置cookie,Request.Cookies用于读取来自浏览器的cookie。

10-06 15:52