ASP.NET关于COOKIE的问题
我给COOKIE的添加键值对的时候,新的键值对会覆盖掉老的键值对,这是什么原因,困扰我半天了。代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["myCookie"] == null)
{
System.Web.HttpCookie cookie= new HttpCookie("myCookie");
ytunionsky.Expires = DateTime.Now.AddHours(24);
Context.Response.Cookies.Add(cookie);
}
System.Random rand = new Random();
int k = rand.Next(0,2);
string CName = k.ToString();
Response.Write(Request.Cookies["myCookie"].Value);
if ((Context.Request.Cookies["myCookie"][CName] == null) || (Context.Request.Cookies["myCookie"][CName].ToString() == ""))
{
Context.Response.Cookies["myCookie"].Values.Add(CName, "test");
}
} --------------------编程问答-------------------- 比如我第一次添加(“1”,“test”)
第二次添加(“2”,“test”),则第二次加的键值对会覆盖掉原来的键值对,也就是说始终保留最新的键值对,请达人解惑
补充:.NET技术 , ASP.NET