Silverlight讀取Cookie指導(dǎo)手冊介紹
Silverlight開發(fā)工具為開發(fā)人員帶來了很大的好處。在多媒體的處理上,幫助開發(fā)人員擺脫以前的種種約束輕松實現(xiàn)各種以前只能依靠美工才能實現(xiàn)的功能。在這里我們先來了解一下Silverlight讀取Cookie的相關(guān)操作方法。#t#
我們要想實現(xiàn)Silverlight讀取Cookie的話,可以通過HtmlPage.Document.GetProperty方法來獲取所有Cookie,另外在HtmlDocument中定義了Cookies屬性,已經(jīng)為我們封裝好了GetProperty方法,可以直接使用,它的定義如下代碼所示:
- public sealed class
HtmlDocument : HtmlObject - {
- public string Cookies
- {
- get{
- HtmlPage.VerifyThread();
- String property = this.
GetProperty("cookie") as String; - if (property != null)
- {
- return property;
- }
- return String.Empty;
- }
- set{
- HtmlPage.VerifyThread();
- String str = value;
- if (String.IsNullOrEmpty(str))
- {
- str = string.Empty;
- }
- this.SetProperty("cookie", str);
- }
- }
- }
如使用下面這段Silverlight讀取Cookie代碼來獲取一個指定Key的Cookie值:
- void btnRetrieve_Click(object
sender, RoutedEventArgs e)- {
- String[] cookies = HtmlPage.
Document.Cookies.Split(';');- foreach (String cookie in cookies)
- {
- String[] keyValues = cookie.Split('=');
- if (keyValues.Length == 2)
- {
- if (keyValues[0].Trim() ==
this.txtKey.Text.Trim())- {
- this.txtValue.Text = keyValues[1];
- }
- }
- }
- }
Silverlight讀取Cookie的具體方法就為大家介紹到這里。