This is a migrated thread and some comments may be shown as answers.

How to Access a Cookie Created in Silverlight from an Asp.net page

2 Answers 227 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 25 May 2011, 04:30 PM
Good Day All

I have another question. I have a Silverlight application and in one of the Silverlight pages i am hosting an Asp.net Page using a RadhtmlContainer(Telerik). I created a Cookie in Silverlight like this

public static void SetCookie(string key, string value)
      {
 
         // string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
          DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
          string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
          HtmlPage.Document.SetProperty("cookie", cookie);
      }

 
and i have the same generic function to access it like this

 
public static string GetCookie(string key)
        {
            string[] cookies = HtmlPage.Document.Cookies.Split(';');
            key += '=';
            foreach (string cookie in cookies)
            {
                string cookieStr = cookie.Trim();
                if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
                {
                    string[] vals = cookieStr.Split('=');
 
                    if (vals.Length >= 2)
                    {
                        return vals[1];
                    }
 
                    return string.Empty;
                }
            }
 
            return null;
        }


so i am trying to access this cookie in an asp.net page that is hosted on the the html Container , but i dont find the cookie.

Basically what i want to Achieve is

i want to access a value that is being created in Silverlight e.g "userid" "Username" normally i store it in the Cookie , so now i want to do a database insert , i need to do that insert from that asp.net page, but i cant get hold of that cookie value.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 28 May 2011, 01:35 PM
Hello Vuyiswa,

Have a look at this blog post and let me know if it helps.

Kind regards,
Kiril Stanoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vuyiswa
Top achievements
Rank 2
answered on 28 May 2011, 04:18 PM
Thank you for your reply, i had a deadline to make a presentation and this was a perfect Solution for me. i ended up doing some nasty things. i stored the values in a Database when i moved to a pay that has htmlContainer(Popup) and retrieve them when i was doing something in the asp.net page that was hosted on the htmlcontainer, and when i a new value i had to truncate the table that was carrying the old value , it was not expansive to do the round trips via WCF m, but it was nasty, when i get time to fix something i will consider that nice cookie manipulation that is done on the client side.

Thanks Kiril
Tags
HTMLPlaceHolder
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Kiril Stanoev
Telerik team
Vuyiswa
Top achievements
Rank 2
Share this question
or