CJe
CJe

Reputation: 1992

Session null when performning multiple ajax calls

Please help as this has been driving me nuts since last week and I'm still not closer to a solution...

Environment: IIS 7.5, .Net 4.0, jQuery (latest)

I have an internal web service that I call to create a hierarchy object consisting of a number of customers and their relations. In my web service I store the hierarchy object in HttpContext.Current.Session.

Shortly there after in my javascript I loop over the customers visible to the user. For each customer I call an $.ajax function that calls another procedure in my web service. In the C# code I read my hierarchy object from HttpContext.Current.Session and using linq reads the data for the current customer.

My problem is that HttpContext.Current.Session["hierarchy"] returns null for some customers. It's not the same customers each time even though I'm calling the exact same url.

I have tried reading the hierarchy from HttpContext.Current.Session immediately after writing it just to verify that everything in my hierarchy object is actually written to HttpContext.Current.Session.

I have tried logging HttpContext.Current.Session.SessionId to verify that the session is the same and everything adds up.

I have tried with and without EnableSessionState in my Default.apsx

Thanks in advance to anyone who can guide me in the right direction...

./CJ

Upvotes: 3

Views: 1805

Answers (2)

Gaff
Gaff

Reputation: 5667

If you are using an ASMX web service (hopefully not) be sure to have the following above each method:

[WebMethod(EnableSession = true)]

Otherwise, Xing is correct concerning WCF. I know from experience that the session will return null if you do not manually turn on ASP.NET sessions.

Upvotes: 2

xing
xing

Reputation: 447

Is your web service made of WCF? If so, there is no session at all unless asp.net compatibility mode is enabled.

Upvotes: 2

Related Questions