Response.Cookies["alertsCookie"]
gives me a blank cookie.
I have made two cookies since I could not find out how to read a cookie in a path, so I decided to write them to both locations (the page path and /)
Code-behind:
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);
}
JavaScript can create, read, and delete cookies with the document.cookie property. With JavaScript, a cookie can be created like this: document.cookie = "username=John Doe"; You can also add an expiry date (in UTC time).
JavaScript can also manipulate cookies using the cookie property of the Document object. JavaScript can read, create, modify, and delete the cookies that apply to the current web page.
Look in Request
instead of Response
.
HttpCookie seenAlertsCookie = Request.Cookies["alertsCookie"];
Response.Cookies
is for setting cookies on the browser, Request.Cookies
is for reading cookies coming from the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With