1

How can I share session like LoginUser value between 2 hosting servers?

I host 2 application one in 10.10.10.120 (IIS 8) and the other on 10.10.10.121 (IIS 8).

I tried use Sql server or NCache server but not worked.

I used same machine Key in 2 apps and same configuration

Note:- I preparing to use Load balance server

shady youssery
  • 430
  • 2
  • 17

1 Answers1

0

I am using NCache and it is working fine for storing sessions in a centralized store. Load balanced applications deployed on two different web servers should be able to use the same session object. I initially used the sample session app which came installed with NCache and then followed below steps which worked for me on the application end.

Session Sharing between same application deployed on two or more Web Servers.

  1. Add NCache Session State Provider Assembly.

    <assemblies>
    <add assembly="Alachisoft.NCache.SessionStoreProvider, Version=4.8.0.0, 
    Culture=neutral, PublicKeyToken=CFF5926ED6A53769" />
    </assemblies>
    
  2. Add NCache Session State

    <sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="NCacheSessionProvider" timeout="1">
                 <providers>
    <add name="NCacheSessionProvider" 
    type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider" exceptionsEnabled="true" nableSessionLocking="true" emptySessionWhenLocked="false" sessionLockingRetry="-1" sessionAppId="NCacheTestApp" useInProc="false" enableLogs="false" cacheName="SessionsCache" writeExceptionsToEventLog="false" AsyncSession="false" />
                 </providers>
    

  3. Keep same machine key across Web Servers in Load balanced Webfarm.

    <machineKey validationKey ="A01D6E0D1A5D2A22E0854CA612FE5C5EC4AECF24"
    decryptionKey ="ACD8EBF87C4C8937" validation ="SHA1"/>
    
  4. Deploy same application on all webservers which are load balanced.

Session Sharing between two different applications deployed on two or more Web Servers.

You can also share session data between two different applications if that’s what you are trying to achieve here.

  1. Keep all above steps same but ensure that two applications have same value for sessionAppId="NCacheTestApp" under SessionState tag.