Using session state in an .asmx web service
You are building an ASP.NET web service and wish to expose some functionality that relies on session state information. A standard .aspx page will handle session state normally but web services do not have acess to the same session data as the rest of your applicaiton.
The trick is that in order to access session state information within a web method you must enable session state management explicitly in your .asmx file as follows:
[WebMethod(EnableSession = true)]
By specifying the EnableSession value you will have a managed session to play with. If you dont set this value the Session object will be null and you will encounter an object reference exception when trying to access the Session object from either this.Session or System.Web.HttpContext.Current.Session.
No comments:
Post a Comment