R – Silverlight, WCF AspNetCompatibilityRequirements and ASPNET Session State not shared

sessionsilverlightwcf

I have a Silverlight application that on a button opens an aspx page in a new browser window.

I want to pass some username/password details from Silverlight to the aspx page. My understanding is that I should be using WCF services to set the session state, which can then be retrieved from the aspx page.

I have followed what I think are the correct steps, but the aspx page refuses to see the state set by Silverlight.

What I have done is;

  • Created a WCF service that sets System.Web.HttpContext.Current.Session["Thing"]
  • On that service, set AspNetCompatibilityRequirements = Required and also set aspNetCompatibilityEnabled="true" on the web.config

My Silverlight application is able to set (and retrieve) session information using this WCF service successfully.

However when I get Session["Thing"] on the aspx page it is blank. Also if I set Session["Thing"] on the aspx page, Silverlight does not get it.

It's as if the two have different sessions – why is this?

Thanks in advance
Matt

Best Answer

Is it possible that the WCF service that your Silverlight client talks to is in a different web app (ie, is there more than one web project)? The default in-proc state provider is really per-appdomain, so if they're in different apps, you'd have two copies of your session state in two appdomains. If this is the case, just move the service code into the same webapp with the pages, and life is good. I can't think of any other explanation- I've done this plenty of times with no trouble.

Related Topic