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

3 posts, 1 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 25 May 2011 Link to this post

    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. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 28 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 28 May 2011 Link to this post

    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
Back to Top