Valid for Sitecore
5.2, 5.3
Session state in web services
In some cases login status may be lost between different calls to a web service. The reason of such behavior does not depend on Sitecore, as a valid session id cookie is not generated by the web service layer until the Session object is actually used.
You can observe the behavior described by following the steps below:
- Create a web service with two methods: Login and GetCurrentUser. Login should call Domain.Login and GetCurrentUser should return Domian.CurrentUser. Remember to EnableSession on the methods.
- Create a Windows application (not just a web page) that calls the two methods (Login first). Remember to use a CookieContainer.
- GetCurrentUser will return null. If you debug, the Login and GetCurrentUser methods will have different Session.SessionID.
- Add the line: Session["dummy"] = "dummy" to the Login method and re-run the test.
- GetCurrentUser will now return the correct user, and if you debug, the Login and GetCurrentUser methods will have the same Session.SessionID.