Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Silverlight 2 -- Set Cookie
9 replies. Latest Post by bezobav on December 25, 2008.
(0)
thenewse...
Member
77 points
31 Posts
03-18-2008 8:29 AM |
Hi All,
How do you set a browser cookie for the page hosting a SL2 app from within that app?
I've read all the documentation and posts on this that I could find and have not found an answer to what should be a simple question...
Thanks for any help.
_T
Anand Tr...
73 points
50 Posts
03-18-2008 8:39 AM |
You can call a Asp.Net server side function with the help of javascript function to save a cookie.
03-18-2008 2:20 PM |
Thanks for the reply. Any sample code for this?
All I'm trying to do is set a cookie in SL2 that the aspx code-behind from another page can check.
jackbond
Contributor
2806 points
722 Posts
03-18-2008 4:38 PM |
thenewsequoyan:Thanks for the reply. Any sample code for this?
How about this? :)
{
}
jeetumaker
525 points
92 Posts
03-18-2008 5:21 PM |
You can also explore the option of IsolatedStorage (IS) in Silverlight. IS is something like "cookies on steriods" where you get more flexibility than the traditional cookie and storate limie is 1MB per Silverlight app which could be extended by taking permission from the user. The main advantage of IS is you could store any object/file streams and only your app gets access to it from alls browser (IE & FireFox) installed on the same machine.
I hope this helps. If so Please click on the "Mark As Answer" .
03-19-2008 8:53 AM |
Mr. Bond,
Thank you very much! That's done it.
Here's a VB.Net version for anyone interested. I've added get & delete methods. Additionally I had to do a little investigation to get cookie debugging working on localhost. It wasn't hard, just needed to pass an empty string to Path for the SetCookie method.
Imports
fullCookie.Append(
HtmlPage.Document.SetProperty(
End
03-19-2008 8:55 AM |
Jeetu,
Thanks for the post.
If you read the scenario in my first post of this thread you'll see that I need to check the cookie in aspx code behind (ie no silverlight) so IS is not an option.
laurent_31
4 points
2 Posts
07-04-2008 3:10 AM |
I repply my question in this post because it's allmost the same.
http://silverlight.net/forums/p/12892/67821.aspx#67821
How to get in a ASP.NET page a cookies who was send by the silverlight application?
Thanks to you,
Sergey.L...
6454 points
1,234 Posts
07-16-2008 3:52 AM |
Hi,
Look here.
bezobav
5 points
4 Posts
12-25-2008 5:44 PM |
DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(250);
string cookie = string.Format("key=value;expires={0}", expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);// string cookie = HtmlPage.Document.GetProperty("cookie");