Multi-Region ASP.NET Session State Provider for NCache
NCache provides Session sharing support across multiple regions. This prevents users from losing their sessions in case you need to reroute your traffic to another location because of traffic or due to disaster recovery. Sessions are replicated across WAN seamlessly without replicating the entire session which may result in bandwidth expense. Figure 1 shows the process flow associated with session sharing across multiple regions.
Figure 1: Session Sharing across Data Centers
Add New Section for Session State Management
Modify <configSections>
section in the application's Web.config and add the
following section which will specify the locations and primary and secondary
caches.
Enterprise Edition:
<configSections>
<section name="ncache" type="Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
</configSections>
Professional and Open Source Editions:
<configSections>
<section name="ncache" type="Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=1448e8d1123e9096"/>
</configSections>
Note
Replace Version=x.x.x.x
with the actual NCache version that you have installed. For example, Version=4.6.0.0
.
- Refer
Alachisoft.NCache.SessionStoreProvider
in your project from[InstallDir]/bin/assembly/[2.0 or 4.0]
folder.
Add a section with the section name specified above (<ncache>
in this case),
under <configuration>
tag in your application's Web.config.
<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>
Note
The sid-prefix is a unique identifier that is appended by custom session-ID manager in the beginning of session-ID.
Modify sessionState Tag
Enable custom sessionID
manager using the sessionIDManagerType
attribute of
the sessionState
element in Web.config and add custom provider.
Member | Description |
---|---|
sessionIDManagerType |
Optional String attribute. Specifies an identifier to make sure that session id remains unique in case multiple applications are using the same cache. Application id should be the same for an application in a web farm. If no app id is specified, nothing will be concatenated with session id. |
<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="NCacheApp"
cacheName="myCache"
writeExceptionsToEventLog="false"
asyncSession="false"
enableLogs="false"/>
</providers>
</sessionState>
When Location Affinity is enabled,
cacheName
specified in<providers>
section of Web.config will be ignored.Cookieless sessions are not supported.