Silverlight读取Cookie指导手册介绍

开发 开发工具
Silverlight读取Cookie的相关操作在开发人员实际编程中是一个非常常见的操作。对于我们刚刚接触这款工具不久的人来说,需要熟练的掌握这些基础应用。

Silverlight开发工具为开发人员带来了很大的好处。在多媒体的处理上,帮助开发人员摆脱以前的种种约束轻松实现各种以前只能依靠美工才能实现的功能。在这里我们先来了解一下Silverlight读取Cookie的相关操作方法。#t#

我们要想实现Silverlight读取Cookie的话,可以通过HtmlPage.Document.GetProperty方法来获取所有Cookie,另外在HtmlDocument中定义了Cookies属性,已经为我们封装好了GetProperty方法,可以直接使用,它的定义如下代码所示:

  1. public sealed class 
    HtmlDocument : HtmlObject  
  2. {  
  3. public string Cookies  
  4. {  
  5. get{  
  6. HtmlPage.VerifyThread();  
  7. String property = this.
    GetProperty("cookie") as String;  
  8. if (property != null)  
  9. {  
  10. return property;  
  11. }  
  12. return String.Empty;  
  13. }  
  14. set{  
  15. HtmlPage.VerifyThread();  
  16. String str = value;  
  17. if (String.IsNullOrEmpty(str))  
  18. {  
  19. str = string.Empty;  
  20. }  
  21. this.SetProperty("cookie", str);  
  22. }  
  23. }  

如使用下面这段Silverlight读取Cookie代码来获取一个指定Key的Cookie值:

 

  1. void btnRetrieve_Click(object
     sender, RoutedEventArgs e)  
  2. {  
  3. String[] cookies = HtmlPage.
    Document.Cookies.Split(';');  
  4. foreach (String cookie in cookies)  
  5. {  
  6. String[] keyValues = cookie.Split('=');  
  7. if (keyValues.Length == 2)  
  8. {  
  9. if (keyValues[0].Trim() == 
    this.txtKey.Text.Trim())  
  10. {  
  11. this.txtValue.Text = keyValues[1];  
  12. }  
  13. }  
  14. }  

Silverlight读取Cookie的具体方法就为大家介绍到这里。

责任编辑:曹凯 来源: 博客园
相关推荐

2010-01-04 16:17:50

Silverlight

2009-12-31 15:58:11

Silverlight

2010-06-03 14:55:59

Hadoop配置

2009-12-18 15:49:05

Ruby Rmagic

2010-09-26 10:02:09

JVM优化配置

2010-07-15 09:10:08

Perl函数手册

2009-12-30 17:23:49

Silverlight

2009-12-29 18:46:41

Silverlight

2014-12-24 10:24:55

Java

2009-12-22 11:14:38

WCF禁用安全配置

2009-12-30 17:19:09

Silverlight

2010-05-19 18:03:07

2010-06-07 18:12:39

mrtg 安装

2010-05-19 18:26:28

SVN服务器安装

2010-10-08 14:31:46

Javascriptsplit函数

2010-08-04 11:23:15

Flex字符串

2009-12-30 15:08:04

Silverlight

2010-09-26 14:44:31

JVM内存监控工具

2009-12-30 14:44:04

Silverlight

2010-01-04 15:21:37

Silverlight
点赞
收藏

51CTO技术栈公众号