急急急 !在网上查了删除cookie的方法都千篇一律是 public static void DeleteCookie(string key)
{
string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}欧诺个了还是不行呀,不能清空,怎么回事
确认一下你写入时与删除时是不是用的同一个key。
删除时直接写入过期的cookie,不需要获取原来的cookie,参考代码(代码来自Cookies for Silverlight):
public static void Delete(string key)
{
DateTime expireDate = DateTime.Now - TimeSpan.FromDays(1); // yesterday
string expires = ";expires=" + expireDate.ToString("R");
string cookie = key + "=" + expires;
HtmlPage.Document.SetProperty("cookie", cookie);
}
谢谢了!问题解决了。非常感谢!