Is it possible to access a Asp.net session variable from a WCF service by using the SessionID.
My service is called from jQuery and my thought was to parse the sessionID using jQuery to the service and then set the needed variables, but I can not find a way to do this.
Here is my jQuery call
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: baseURL,
data: JSON.stringify(data),
dataType: "json",
success: function (data) {
Does anyone know if it is at all possible or suggest another way set a session related variable?
The jQuery request from the browser will already include the session cookie, so if you’re running your WCF service in ASP.NET compatibility mode it already has direct access to the current
HttpContextwhich means you can access the Session State from there. Here’s how you can enable this integration on your WCF service:First, add the following attribute to your service class:
Next, add the following to your service .config:
Once you do this you can access the current
HttpContextto grab the Session State like so: