WEB开发网
开发学院图形图像Flash 技巧:在Silverlight应用程序中操作Cookie 阅读

技巧:在Silverlight应用程序中操作Cookie

 2008-10-09 11:39:57 来源:WEB开发网   
核心提示: public sealed class HtmlDocument : HtmlObject{public string Cookies{get{HtmlPage.VerifyThread();String property = this.GetProperty("cookie&q

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);
    }
  }
}

如使用下面这段代码来获取一个指定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

Tags:技巧 Silverlight 应用程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接