Silverlight读取与设置Cookies

设置Cookie

DateTime expire = DateTime.UtcNow + TimeSpan.FromDays(30);

string cookie = string.Formate("{0}={1},expires={2}",key,value,expire)

HtmlPage.SetProperty("cookie",cookie);

读取Cookie

由于读取到的Cookie是一个集合,所以需要遍历它。

string result="";


string[] cookies = HtmlPage.Document.Cookies.Split(';');

foreach(string cookie in cookies)

{
     string cooArr = cookie.split('=');
     if(cooArr.Length >=2)
     { 
          result = cooArr[1];
     }
}
原文地址:https://www.cnblogs.com/rentianlong/p/2552555.html