Step 2: Edit web.config or machine.config
After you have configured the cache and have named it 'myQSReplicatedCache', you now need to configure your ASP.NET application to use the Clustered Session HTTP Module that is provided with NCache installation. To do so, you must edit web.config file.
Please follow these steps for enabling NCache Session State Module to transparently save and retrieve ASP.NET session-state objects.
-
Edit your application's web.config file to add <appSettings> entry under <configuration> section.
<appSettings>
<add key = "CacheName" value = "myQSReplicatedCache "/>
<add key = "sessionAppId " value = " 1234 "/>
<add key = "exceptionsEnabled " value = " true "/>
<add key = "enableLogs " value = " false " />
<add key = "enableDetailLogs " value = " false "/>
<add key = "clearASPSession " value = " false "/>
<add key = "writeExceptionsToEventLog " value = " false "/>
<add key = "operationRetries" value = "0"/>
<add key = "operationRetryInterval" value = "0"/>
</appSettings>
-
Add <httpmodules> entry under <system.web> section in web.config.
For Enterprise and Professional Edition:-
<httpModules>
<add name = "NCacheWebSessionState" type = "Alachisoft.NCache.Web.SessionState.NSessionStateModule,
Alachisoft.NCache.SessionState, Version=x.x.x.x, Culture=neutral, PublicKeyToken=cff5926ed6a53769"/>
</httpModules>
For Open Source Edition:-
<httpModules>
<add name = "NCacheWebSessionState" type = "Alachisoft.NCache.Web.SessionState.NSessionStateModule,
Alachisoft.NCache.SessionState, Version=x.x.x.x, Culture=neutral, PublicKeyToken=1448e8d1123e9096"/>
</httpModules>
|
Replace version “x.x.x.x” with the actual NCache version that you have.
|
-
Add <machinekey> entry under <system.web > section in the web.config. It is required to generate ASP.NET session IDs in the same manner on all nodes.
<machineKey validationKey = "A01D6E0D1A5D2A22E0854CA612FE5C5EC4AECF24" decryptionKey = "ACD8EBF87C4C8937" validation = "SHA1"/>
Enable Location Affinity for HttpModule
1. Add following section in web.config.
For Enterprise and Professional Edition:-
<configSections>
<section name = "ncache" type = "Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/>
</configSections>
<ncache>
<sessionLocation >
<primaryCache id = "myQSReplicatedCache" sid-prefix = "abcd"/>
<secondaryCache id = "myQSReplicatedCache2" sid-prefix = "pqrs"/>
<secondaryCache id = "myQSReplicatedCache3" sid-prefix = "wxyz"/>
</sessionLocation>
</ncache>
For Open Source Edition:-
<configSections>
<section name = "ncache" type = "Alachisoft.NCache.Web.SessionStateManagement.NCacheSection,
Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=1448e8d1123e9096"/>
</configSections>
<ncache>
<sessionLocation >
<primaryCache id = "myQSReplicatedCache" sid-prefix = "abcd"/>
<secondaryCache id = "myQSReplicatedCache2" sid-prefix = "pqrs"/>
<secondaryCache id = "myQSReplicatedCache3" sid-prefix = "wxyz"/>
</sessionLocation>
</ncache>
Please keep the followinf points in mind:
-
Replace version “x.x.x.x” with the actual NCache version that you have.
-
The sid-prefix is a unique identifier that is appended by custom session-ID manager in the beginning of session-ID. sid-prefix length must be equal to 4.
-
When Location Affinity is enabled, "CacheName" specified in <appSettings> section of web.config will be ignored.
2. Enable custom session-ID manager using the sessionIDManagerType attribute of the sessionState element in web.config.
<sessionState mode = "InProc" cookieless = "true" timeout = "20" sessionIDManagerType = "Alachisoft.NCache.Web.SessionStateManagement.CustomSessionIdManager, Alachisoft.NCache.SessionStateManagement"/>
|
Custom session-ID manager is only supported for .NET 2.0 and later. Thus, for any applications build with earlier versions of .NET, Custom session-ID manager is not required.
|
See Also