0

So, I have on same machine asp.net app and wcf service. And I'm trying to share asp.net session between them. I have configured Sql server to store my session data. I have ASPState Db and two tables in tempdb: ASPStateTempSessions, ASPStateTempApplications And both have rows with data. In asp.net app and wcf service configs I have added :

<sessionState mode="SQLServer" sqlConnectionString="Data Source=localhost;integrated security=True;Application Name=app" />

In Asp.net app I set user like this

HttpContext.Current.Session["User"] = userName;

In logs I saw an entry that user was actually setted. (and checked via JS)

In wcf service:

[ServiceContract(SessionMode = SessionMode.Allowed)]
    public interface IDbWebService
    {
        [OperationContract]
        [WebInvoke]
        Data GetBlahBlah(string env);
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public partial class WebService : IDbWebService
    {
          public  Data GetBlahBlah(string env)
          {
                 //trying to get data here, nothing, just null
                _log.InfoFormat("USER: {0}", HttpContext.Current.Session["User"]); 

          }
}

But I cannot get Session["User"].

What I'm doing wrong, maybe I have missed something obvious ?

Thanks in advance!

Andriy Khrystyanovich
  • 1,422
  • 3
  • 19
  • 38

1 Answers1

0

See this post:

Losing Session State with ASP.NET/SQL Server

Make sure your application ID's are the same in IIS manager and that you have the same machine key set in both configs. Both are used in the generation and encryption of session state, so if they are different you will not be able to share session entries.

On a separate note, relying on Session State to pass information between an application and a web service would seem to violate layered responsibility patterns. Your web service is now reliant on the client to provide data through this backdoor means that is not represented anywhere in the service contract. Another client consuming the service would have to provide data in the same fashion in order for the service to function correctly. Is there a reason why the data can't be supplied in the method signature?

Community
  • 1
  • 1
Jason
  • 651
  • 5
  • 10