我使用多维cookie在我的应用程序中存储cookie。 例如
HttpCookie MyCookie = Request.Cookies["Temp"] as HttpCookie;
if (MyCookie != null)
{
MyCookie.Values["SID"] = Session.SessionID;
MyCookie.Values["NAME"] = "NAME";
MyCookie.Values["abc"] = "abc";
MyCookie.Values["xyz"] = "xyz";
...
}
现在检索我使用过的多维cookie。
string s = Request.Cookies["Temp"]["SID"]
我的问题是我想要从“Temp”cookie中过期“SID”值。我试过这个
Request.Cookies["Temp"]["SID"] = null;
但它不起作用。我该怎么做才能从多维cookie中清除特定索引?
答案 0 :(得分:0)
这样做。
Request.Cookies["Temp"].Values["SID"] = null;
希望它有所帮助。 :)
答案 1 :(得分:0)
以下问题已经回答了这个问题:ASP.NET Cookie Sub-Value Deletion
HttpCookie.Values是一个NameValueCollection,因此您可以修改该集合 - 但您需要重新发送cookie作为新的cookie来覆盖旧的:
HttpCookie cookie = Request.Cookies["Temp"];
if(cookie != null)
{
cookie.Values.Remove("SID");
Response.AppendCookie(cookie);
}
以下MSDN页面也对此进行了解释:http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx#vbtchaspnetcookies101anchor9