views:

1311

answers:

2

Hi,

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

A: 

As far as I can tell, if you open the page in a new browser window, it will create a new session. Your only hope of having the session shared is to create a shared object at the web server level (ugly).

Why don't you just pass the state as a querystring? Or open the page in an HtmlHost link text element withing SL?

R4cOON
The information being passed are authentication details for a report that the aspx page is running, so I don't want to use a query string or cookies to hold that information.I had looked at the HtmlHost from ComponentOne - but doesn't this give me the same problem, i.e. passing information to the aspx page within the HtmlHost?
Matt Swanton
Did you have a look at the SessionId passed around? You could pass that around to get your stored data. Is the value really different in the service and aspx page calls?The only issue I had with sessions was that I had to remove and reset the Authentication module on IIS 7 to get the user credentials for the HTTP handlers.
R4cOON
The Session ID is the same. I suppose I could persist the data in SQL on the server, but I was hoping to keep it simple.
Matt Swanton
Now I just remembered that I experienced that issue with my HTTP handler as well. I saved files in the Session object and it worked fine for my IE8 but the session was always empty for FF or IE7 :(I resorted to the ugly hack of saving the session to disk (I needed to save files).
R4cOON
A: 

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.

nitzmahone
Yes! This is exactly what it was. I have my services in a different project and added this session management service it. I moved the session management service into the aspnet application and it now works fine - thank you!
Matt Swanton