client = IE9, server = asp.net (a sharepoint application page to be exact)
In the Page_Load
method of a page, I have the following code:
Response.Cookies["XXXXX"].Value = tabtitles.IndexOf(Request.Params["tab"]).ToString();
Response.Cookies["XXXXX"].Expires = DateTime.Now.AddDays(1);
My cookie logic wasn't behaving as expected, so using the Console in IE Developer Tools I've found that document.cookie
had the following value:
>> document.cookie
"XXXXX=3; WSS_KeepSessionAuthenticated={7da6dcd3-28b6-4c8f-b507-6fa80a16143c}; databaseBtnText=Open%20with%20Access; databaseBtnDesc=Works%20with%20items%20in%20a%20Microsoft%20Access%20database%2E; XXXXX=7"
as you can see, the cookie was appended to the end of document.cookie
instead of replaced. is this a bug in IE9? How can I correctly set and get the cookie i want?
The problem was that I had earlier set a cookie with the jquery plugin, which sets the current path as that path for the cookie. The above .Net code sets the path of the added cookie to "/"
, so there was two different cookies present, which was invisible to me when viewing the document.cookies
variable. My solution was to set the path of the jquery cookie to be "/"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.