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',7300); } else { var cookieVal = cookie + '|'; cookieVal = cookieVal + alertGuid; $.cookie('alertsCookie',cookieVal,7300); }
解决方法
查看请求而不是响应.
HttpCookie seenAlertsCookie = Request.Cookies["alertsCookie"];
Response.Cookies用于在浏览器上设置cookie,Request.Cookies用于读取来自浏览器的cookie.