using System.Windows.Browser;
寫入cookie:以下內容會將「Key=Nothing」寫入cookie中
DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
string cookie = String.Format("{0}={1};expires={2}",
"Key", "Nothing", expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
刪除cookie內容值:以下內容會將「Key」值移除
DateTime expireDate = DateTime.Now - TimeSpan.FromDays(1);
string expires = ";expires=" + expireDate.ToString("R");
string cookie = "Key=" + expires;
HtmlPage.Document.SetProperty("cookie", cookie);
讀取cookie內容值:以下將會找出「Key」的內容值,並以MessageBox提示
String[] cookies = HtmlPage.Document.Cookies.Split(';');
string key = "Key=";
foreach (string s in cookies)
{
string ck = s.Trim();
if (ck.StartsWith(key, StringComparison.OrdinalIgnoreCase))
{
string[] vals = ck.Split('=');
MessageBox.Show(vals[1]);
}
}
沒有留言:
張貼留言