0

I'm writing a jQuery Mobile app that makes several AJAX requests to a few different IHttpHandler classes on my server. The handlers all return JSON or JSONP, and include the context.Session.SessionID in the JSON, for debugging purposes. I make one request to the first handler, and get back session ID "2jysbehwyxlne0knatltcb2z". I make another request to a different handler, and get back session ID "qy3v251fxrxesbgqeobqvaza". This is within a few seconds of each other. What is going on? I would expect the session ID to be the same until the session expires after an extended time.

When I open the requests in their own tabs, as opposed to via AJAX in the same tab, I get the same session ID back. So for my request to authenticate and then my other request to retrieve data, when these requests happen as AJAX requests in a page, the session IDs are different. When I browse the Network tab in Chrome's console and right-click, Open Link in New Tab each of the requests, they function as expected, having the same session ID.

I am running the jQuery Mobile application on http://localhost, and making requests to handlers at https://localhost, if this matters. All of my handlers implement IRequiresSessionState. This question looks the same as mine, and its only answer is to implement IRequiresSessionState, which I'm doing already.

Edit: this question might be related, but I'm observing this behavior in Chrome.

Edit: I'm using jQuery's getJSON function to make the AJAX request. This question about getJSON and cookies might be relevant.

Community
  • 1
  • 1
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
  • 1
    Have you checked that your cookies are being passed properly? Check if the value is set in your asp.net session cookie – nunespascal Jun 22 '12 at 21:21
  • Looks like the cookie only gets set when I make a regular HTTP request to the handler in a browser tab. I see the session ID in the cookie that was returned in my JSON that way. When I then try to load my page where the request is made via AJAX, the session ID in the cookie remains the same, and the session ID returned via the AJAX request is different from the one in the cookie. – Sarah Vessels Jun 25 '12 at 13:44
  • Could you share your ajax calling code? And also your current domain. There must be something wrong there. – nunespascal Jun 26 '12 at 03:38
  • Hm, I'm using jQuery's `getJSON` function. I'll update my question with a related link. – Sarah Vessels Jun 26 '12 at 18:12

1 Answers1

0

I think my problem may have been that I was using jQuery's getJSON method for sending the AJAX request. I ended up adding <sessionState cookieless="true" /> to my Web.config, so now my handlers stick S(the_session_id)) into the URL. When I send my first request to the handler, I store the session ID returned in my JSON in HTML 5 local storage. All subsequent requests, I pass that session ID in the URL. This isn't an ideal solution, and I may investigate further to see if I can use cookies for my session again.

Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222