Walkthrough: Configuring a shared session state database using the MongoDB provider
In shared session state, all data that can be shared across multiple sessions, for example, the data related to contacts and devices, is collected and saved to the session state database.
You must always configure shared session state whatever your server configuration. For example, you can have a single standalone content delivery server, multiple content delivery servers, or a clustered environment, but you always need to configure session state.
Shared session state is not supported on content management servers.
A contact can make multiple parallel visits to a website in which case each visit has its own private session state. However, some data can be shared between visits, such as device and contact related information.
Information that is shared between parallel visits by the same contact is stored in the shared session-state store. This data is still private to the contact but it is accessible from all current sessions made by the same contact.
You can use either the Sitecore MongoDB or Sitecore SQL Server providers to configure your shared session-state store. Both these providers support the SessionEnd event that the xDB needs to track website visits.
The standard OutOfProcSessionStateStore
that is shipped with ASP.NET does not support the SessionEnd
event and therefore cannot be used with shared session state.
You can configure shared session state to use any session-state store provider that extends the abstract class SessionStateStoreProviderBase
(shipped with ASP.NET). The only additional requirement is that the session-state store provider can invoke the SessionEnd
event via SessionStateItemExpireCallback
.
If you are using the xDB Cloud Edition, using the shared session state provider for MongoDB is not included as part of this service.
Follow the steps in this section to use a MongoDB database as your shared session state store using the Sitecore ASP.NET Session State Provider for MongoDB:
Deploy a MongoDB session database
The Sitecore ASP.NET Session State Provider for MongoDB enables you to use MongoDB as your session state store. The provider supports the SessionEnd event, which the xDB needs to track website visits.
To deploy a MongoDB session database:
-
Install the MongoDB database server version 2.6 or later on a dedicated server using the instructions on the MongoDB website.
-
In a suitable XML editor, open the
ConnectionStrings.config
file located here:<sitename>\Website\App_Config
and add the following connection string:RequestResponse<add name="sharedsession" connectionString="mongodb://_mongo_server_name_:_port_number_/_session_database_name_" />
-
Configure the connection string so that it points to your session database.
-
Save your changes.
Configure Sitecore
To configure Sitecore to use the shared session-state provider for MongoDB:
-
In your website root folder, navigate to
Website\App_Config\Include
. -
Open the
Sitecore.Analytics.Tracking.config
file. -
Locate the line where you can define the default shared session state provider using the following path:
sitecore/tracking/sharedSessionState
. -
The default shared session store uses inProc provider (storing data in memory and implemented in the internal ASP.NET class InProcSessionStateStore):
RequestResponse<sharedSessionState defaultProvider="inProc"> <providers> <clear/> <add name="inProc" type="System.Web.SessionState.InProcSessionStateStore" /> </providers> </sharedSessionState>
NoteFor clustered environments, Sitecore ships with a MongoDB session state store provider.
-
To configure MongoDB as your shared session-state store provider, change the
defaultProvider
frominProc
tomongo
. Also, change the name attribute value tomongo
.RequestResponse<sharedSessionState defaultProvider="mongo"> <providers> <clear/> <add name="mongo" type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider, Sitecore.SessionProvider.MongoDB" connectionStringName="sharedsession" pollingInterval="2" compression="true" sessionType="shared"/> </providers> </sharedSessionState>
Adjust session state settings
In Sitecore, when you configure a session state, you have the following configuration options:
Setting |
Description | |
---|---|---|
|
Contains the connection string that Sitecore uses to connect to the session database. Edit to specify the session state database that you want to use. In the xDB, this database is called session. |
For example:
|
|
Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired. |
For example:
|
|
Indicates that you want session-state data to be compressed. The default value is true. Compressing session state data reduces the amount of data that you need to transfer between the database and the Sitecore instance. This may cause some additional CPU overhead. |
For example:
|
|
Indicates whether the type of session state is private or shared. |
For example:
|