views:

2545

answers:

4

I was told this works, but...

I guess I'm just not getting this, it seems there's a hidden step I may be missing, can anyone correct this or point out my mistake? Thanks.

I have a blank solution:
- inside is two .net 2.0 web applications
1) webapp1
2) webapp2

I want them to share the same session data.

My page setups:

Application 1:

Session("value") = "this is the value"

Application 2:

If Not (Session("value") Is Nothing) Then
    value = Session("value").ToString()
End If

My thought process:

1) go to services, turn on the asp.net state service
2) open the web configs in both projects: set the

< machineKey 
validationKey="BFE2909A81903BB303D738555FEBC0C63EB39636F6FEFBF8005936CBF5FEB88CE327BDBD56AD70749F502FF9D5DECF575C13FA2D17CA8870ED21AD935635D4CC" 
decryptionKey="2A86BF77049EBA3A2FA786325592D640D5ACD17AF8FFAC04" validation="SHA1" />
< sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" 
cookieless="false" timeout="20"/>

in both sites.
3) compile and test the site
4) become disappointed because it does not work. I never see the session from the second webapp.

+1  A: 

You cannot share sessions between different ASP.NET applications without some custom code. What you did in web.config was to use an out of process sessions, which means that data will no longer reside into memory but into the memory of a dedicated machine. This is useful for server farms and it uses the ApplicationName to know which application the session belongs to. So basically your applications need to have the same name if you want them to share sessions. There are some dirty workarounds though.

Darin Dimitrov
that work around did not work for me, and it looks like it did not work for almost anyone there as well... how do you set the application name? i cannot use an sql server, i need to use state server, or in process..
Greg R
were you able to get thos workaround to "work"
Greg R
In my personal experience, I never had to share session state between two different ASP.NET applications so I cannot guarantee. The solution on CodeProject seems hacky but IMHO it should work.
Darin Dimitrov
+1  A: 

They will share session data if they are in the same app pool and the session mode is set to inproc. The way that stateserver and sqlstate work is they use the root of your web address as logical boundaries.

Eg if they are both hosted on the same address and port (or 'site' in iis) but in different sibfolders then they should share session I think.

Matthew Steeples
that will work because the projects would be compiled as one project, yes, however we dont want that, we want to compile both projects separate, and then deploy them side by side - different virtual directories.
Greg R
+1  A: 

Additionally both apps must run on the same domain so that user browser use one cookie to store session id.

Bartek Szabat
A: 

Why do you want to share Sessions between applications?

ASP.NET Session is a metaphor for a user's current interaction with one ASP.NET application. It exists in ASP.NET to give us a place to store temporary state data between the various page requests that a user makes while using your application.

If your applications are very closely related, e.g. the user uses both at the same time, or almost the same time, you could consider merging them into a single ASP.NET application.

If your applications are not that closely related, perhaps they should be sharing the same database as a means to exchange data, or using an API e.g. based on Web Services to exchange information.

Hope that helps.

saille