必须使用CookieCollection
可以有效处理path等多余参数
字符串的形式不方便处理
[C#] 纯文本查看 复制代码 public CookieCollection UpdateCookie(CookieCollection OldCookie, CookieCollection NewCookie)
{
if (NewCookie!=null)
{
for (int i = 0; i < NewCookie.Count; i++)
{
int index = CheckCookie(OldCookie, NewCookie[i].Name);
if (index >= 0)
{
OldCookie[index].Value = NewCookie[i].Value;
}
else
{
OldCookie.Add(NewCookie[i]);
}
}
}
return OldCookie;
}
private int CheckCookie(CookieCollection Cookie,string Name)
{
for (int i = 0; i < Cookie.Count; i++)
{
if (Cookie[i].Name==Name)
{
return i;
}
}
return -1;
}
|