ASP.NET与Silverlight(aspx与xaml) Cookies传值

silverlight:

        ///<summary>
/// Silverlight 创建cookie
///</summary>
DateTime expries = DateTime.UtcNow + TimeSpan.FromDays(1);
string cookie = string.Format("{0}={1};expries={2}", "username",Value,expries);
HtmlPage.Document.SetProperty("Cookie", cookie);
///<summary>
/// Silverlight Read cookie
///</summary>
String[] cookies = HtmlPage.Document.Cookies.Split(';');
foreach (String cookie in cookies)
{
String[] keyValues = cookie.Split('=');
{
if (keyValues[0].Trim() == "username")
{
MessageBox.Show(keyValues[1].Trim());
}
}

}

aspx:

        ///<summary>
/// Creat cookie
///</summary>
HttpCookie cookie = new HttpCookie("username");
cookie.Value = Value.Trim();
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
///<summary>
/// Read cookie
///</summary>
HttpCookie cookie = Request.Cookies["username"];
Value=cookie.Value;



你可能感兴趣的:(silverlight)