1

I have two web applications hosted on a server using virtual directories created on IIS.

like : 123.12.23.124/site1 , 123.12.23.124/site2

Now i need to access the session created in site1 in site2. This is what i have done so far:

  1. change both site's web.config files to use stateserver session as

sessionState mode="StateServer" cookieless="false" timeout="720" stateConnectionString="tcpip=127.0.0.1:42424"

  1. I went into services and started asp.net state service on the server.

I have set up session as on site1:

session["user"] = "xxxx";

And accessing in site2 as :

if(session["user"] != null)
{
}
else
{
   //Always coming here
}
user1882705
  • 1,081
  • 4
  • 15
  • 43
  • Are the virtual directories running under the same app domain in IIS? – Cam Bruce Aug 15 '14 at 17:39
  • Possible duplicate of: http://stackoverflow.com/questions/2868316/sharing-sessions-across-applications-using-the-asp-net-session-state-service – GVashist Aug 15 '14 at 17:45
  • 1
    you must use shared session this link can be use full [Shared Session][1] [1]: http://stackoverflow.com/questions/2868316/sharing-sessions-across-applications-using-the-asp-net-session-state-service – Mehdi Haghshenas Aug 15 '14 at 17:48
  • You can't with default session implementations and no hacks. There are many related questions (i.e. one as suggested duplicate, or http://stackoverflow.com/questions/623551/can-you-share-the-session-variables-between-two-net-2-0-applications?rq=1 ). Please check related posts out and update your questions with what approaches *do not* work for you. (Or close as duplicate if you found one you like) – Alexei Levenkov Aug 15 '14 at 18:37

2 Answers2

0

You set the session server wrong in web.config,

sessionState mode="StateServer" cookieless="false" timeout="720" stateConnectionString="tcpip=127.0.0.1:42424"

It shouldn't be 127.0.0.1. Find and fill the state server's real ip.

desert
  • 29
  • 3
  • This should be comment, and it is also not related to the problem - "how to bypass default session state implementations restriction on not sharing state between different sites". – Alexei Levenkov Aug 15 '14 at 18:35
  • It is just configuration in web.config. I don't think there need extra "bypass". – desert Aug 15 '14 at 18:44
0

It was 2 way for this 1- using shared session that discous in Shared Session 2- using machine key If your problem about authentication ,etc this is very usefull because when you login in one site you logined in other sites on the same server

With manually generated key values, the settings should be similar to the following example.

<machineKey  
validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7
               AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"           
decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
validation="SHA1"
decryption="AES"
/>
Community
  • 1
  • 1
Mehdi Haghshenas
  • 2,433
  • 1
  • 16
  • 35