概述
很多朋友來信問如何在Silverlight
在使用HtmlPage
寫入Cookie
在Silverlight 應用程序中
{
DateTime expir = DateTime
String cookie = String
this
this
expir
HtmlPage
}
這裡設置Cookie的過期時間為一周
如使用下面的界面寫入Cookie
讀取Cookie
我們可以通過HtmlPage
{
public string Cookies
{
get{
HtmlPage
String property = this
if (property != null)
{
return property;
}
return String
}
set{
HtmlPage
String str = value;
if (String
{
str = string
}
this
}
}
}
如使用下面這段代碼來獲取一個指定Key的Cookie值
{
String[] cookies = HtmlPage
foreach (String cookie in cookies)
{
String[] keyValues = cookie
if (keyValues
{
if (keyValues[
{
this
}
}
}
}
如下圖所示
刪除Cookie
刪除Cookie非常簡單
{
DateTime expir = DateTime
string cookie = String
this
HtmlPage
}
Cookie幫助類
由於在開發中
當然如果你還有別的需求
public class CookiesUtils
{
public static void SetCookie(String key
{
SetCookie(key
}
public static void SetCookie(String key
{
SetCookie(key
}
public static void SetCookie(String key
String path
{
StringBuilder cookie = new StringBuilder();
cookie
if (expires
{
DateTime expire = DateTime
cookie
}
if (!String
{
cookie
}
if (!String
{
cookie
}
if (secure)
{
cookie
}
HtmlPage
}
public static string GetCookie(String key)
{
String[] cookies = HtmlPage
String result = (from c in cookies
let keyValues = c
where keyValues
select keyValues[
return result;
}
public static void DeleteCookie(String key)
{
DateTime expir = DateTime
string cookie = String
key
HtmlPage
}
public static bool Exists(String key
{
return HtmlPage
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12979.html