简体   繁体   English

Cookie在document.cookie中重复

[英]Cookie duplicated in document.cookie

client = IE9, server = asp.net (a sharepoint application page to be exact) 客户端= IE9,服务器= asp.net(确切地说是一个共享点应用程序页面)

In the Page_Load method of a page, I have the following code: 在页面的Page_Load方法中,我有以下代码:

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: 我的cookie逻辑不符合预期,因此使用IE开发人员工具中的控制台,我发现document.cookie具有以下值:

>> 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. 如您所见,该cookie被附加到document.cookie的末尾,而不是被替换。 is this a bug in IE9? 这是IE9中的错误吗? How can I correctly set and get the cookie i want? 如何正确设置并获取我想要的Cookie?

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. 问题是我之前用jquery插件设置了一个cookie,该插件将当前路径设置为该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. 上面的.Net代码将添加的cookie的路径设置为"/" ,因此存在两个不同的cookie,当我查看document.cookies变量时,它们对我不可见。 My solution was to set the path of the jquery cookie to be "/" . 我的解决方案是将jquery cookie的路径设置为"/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM