如何通过名称清除主cookie数组中的cookie值 [英] How to clear cookie value by its name which is in array of the main cookie
问题描述
我创建了一个名为"MAINCOOKIE"的主cookie,并继续将动态cookie添加到"MAINCOOKIE"中.我只想从服务器端或客户端的cookie列表中删除所选的cookie.我尝试在服务器端进行清除,但能够清除整个MAINCOOKIE,而无法清除仅在IE中的"MAINCOOKIE"内部的特定cookie,它可以在FF中正常工作.因此,我尝试从客户端删除,但找不到从"MAINCOOKIE"中删除特定Cookie的选项.
在此先感谢
Hi,
I have created a main cookie say "MAINCOOKIE" and with that I keep adding the dynamic cookies into "MAINCOOKIE". I want to delete only the selected cookie from the list of cookies either server side or Client side. I tried clearing in server side, I am able to clear the entire MAINCOOKIE whereas I am not able to clear a particular cookie which is inside "MAINCOOKIE" only in IE, It works finein FF. So I tried deleting from clientside, but I find no option to delete the specific cookie from the "MAINCOOKIE"
Thanks in advance
推荐答案
这是我添加Cookie的方式
This is how i add my cookie
if (Request.Cookies["MainCookie"] != null)
{
if (Request.Cookies[MainCookie].Values["subcookie_" + productId] != null)
{
existingProductId = productId;
existingCookie = Request.Cookies["MainCookie"].Values["subcookie_" + productId].ToString();
string[] splitCookie = existingCookie.Split(''
''); quantity += Convert.ToInt32(splitCookie[1]); isCookieExistAlready = true; HttpCookie aCookie; aCookie = new HttpCookie(Request.Cookies["MainCookie"].Values["subcookie_" + productId]); aCookie.Expires = DateTime.Now.AddDays(-1); } } else { HttpCookie mainCookie = new HttpCookie("MainCookie"); Response.Cookies.Add(mainCookie); } string nameofCookie = string.Concat("subcookie_", (isCookieExistAlready ? existingProductId : productId)); Request.Cookies["MainCookie"].Values[nameofCookie] = productId + "
''); quantity += Convert.ToInt32(splitCookie[1]); isCookieExistAlready = true; HttpCookie aCookie; aCookie = new HttpCookie(Request.Cookies["MainCookie"].Values["subcookie_" + productId]); aCookie.Expires = DateTime.Now.AddDays(-1); } } else { HttpCookie mainCookie = new HttpCookie("MainCookie"); Response.Cookies.Add(mainCookie); } string nameofCookie = string.Concat("subcookie_", (isCookieExistAlready ? existingProductId : productId)); Request.Cookies["MainCookie"].Values[nameofCookie] = productId + "
" + quantity; Request.Cookies["MainCookie"].Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(Request.Cookies["MainCookie"]);
" + quantity; Request.Cookies["MainCookie"].Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(Request.Cookies["MainCookie"]);
添加后,我只想从Maincookie中删除特定的子cookie
我该怎么办?
After Adding I want to delete only particular subcookie from the Maincookie
How do I do that?
这篇关于如何通过名称清除主cookie数组中的cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!