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

Dani AI

Generated

Short answer: an ASP.NET page will only see a cookie if the browser actually sends it on the HTTP request that loads that page. created the cookie from Silverlight (client-side); is correct that the server reads cookies with Request.Cookies. If Request.Cookies is empty for that name, the browser didn’t include the cookie — usually because of origin/path/port differences, embedding/third‑party restrictions, SameSite/Secure policies, or because the container hosts the page in a different HTML/browser context.

Practical checks and quick fixes:

  • Confirm the cookie exists in the browser (DevTools → Application/Storage → Cookies) and note Domain, Path, Expires, HttpOnly, Secure and SameSite attributes.
  • Capture the HTTP request for the hosted ASP.NET page (Network tab or Fiddler) and verify the Cookie header actually contains the name/value.
  • If the ASP.NET page is on a different host/port/subdomain, set the cookie’s Domain and Path so it’s sent to that origin; for cross‑site embedding consider SameSite=None and Secure. Example cookie value format:
userid=42; path=/; domain=.example.com; expires=Fri, 31 Dec 2030 23:59:59 GMT; SameSite=None; Secure

Server-side examples (C#) — reading and setting a cookie:

HttpCookie c = Request.Cookies["userid"];
string userId = c != null ? c.Value : null;
var cookie = new HttpCookie("userid", "42") {
  Expires = DateTime.UtcNow.AddYears(5),
  Domain = ".example.com",
  Path = "/"
};
Response.Cookies.Add(cookie);

If cookie-sharing still fails (embedded container or third‑party blocking), use an explicit server call from Silverlight (WCF/Web API/REST) to perform the insert, or pass the value in a query string/post when navigating to the ASP.NET page. In short: confirm presence in the browser, confirm it’s included in the request, then adjust Domain/Path/SameSite or switch to a direct server call.

for getting cookies in asp.net...use Request.Cookies("cookiesname").value

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.