NCache provides ability to manage ASP.NET session state across multiple web farms. This improves high availability and fault tolerance by allowing web farms to spread across multiple geographic regions. To achieve this, NCache provides Location Affinity feature for sessions.
To understand Location Affinity feature for sessions, consider the following scenario. Suppose that you have created multiple clustered caches, one for each geographical location. Each clustered cache has its own set of clients as a web farm. These clients will add, insert, and get sessions mostly from their own clustered cache. However, some of the times, a user might be sent to the web farm of another geographical location. Now, NCache allows that user to still be able to access the same session, based on the original session id.
This is further explained with the help of following diagram:
This figure demonstrates the following ASP.NET session state scenario:
To use Location Affinity, you will need to specify one 'primary' and one or more 'secondary' caches for each web farm in web.config. The primary cache will be used for all local traffic and all secondary caches will be used when a user goes to different geography.
<configSections>
<section
name = "ncache"
type = "Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
Alachisoft.NCache.SessionStateManagement, Version=3.8.X.X, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
</configSections>
<ncache>
<sessionLocation>
<primaryCache id = "London_Cache" sid-prefix = "LDC"/>
<secondaryCache id = "NewYork_Cache " sid-prefix = "NYC"/>
<secondaryCache id = "Tokyo_Cache" sid-prefix = "TKC"/>
</sessionLocation>
</ncache>
sessionIDManagerType
attribute of the sessionState
element in web.config.
<sessionState cookieless = "false" regenerateExpiredSessionId = "true" mode = "Custom" customProvider = "NCacheSessionProvider" timeout = "60" sessionIDManagerType = "Alachisoft.NCache.Web.SessionStateManagement.CustomSessionIdManager, Alachisoft.NCache.SessionStateManagement">
<providers>
<add name = "NCacheSessionProvider" type = "Alachisoft.NCache.Web.SessionState.NSessionStoreProvider"
sessionAppId = "1234" cacheName = "myCache" writeExceptionsToEventLog = "false" asyncSession = "false"
enableLogs = "false"/>
</providers>
</sessionState>
Note:
Using Session State Module | Using Session State Store Provider