Walkthrough: Configuring a private session state database using the MongoDB provider
In private session state, all data related to a specific interaction, such as viewed pages, converted goals, triggered campaigns, or accumulated engagement points, is collected and saved to the session state database.
You can use either MongoDB or SQL Server as your private session state store. SQL Server might be an appropriate option if you are running the collection database (MongoDB) in the cloud as a service, or if you prefer not to run an on-premise MongoDB server instance.
This walkthrough describes how to use a MongoDB database as your private session state store using the Sitecore ASP.NET Session State Provider for MongoDB:
If you are using a MongoDB session provider, all content delivery servers should use the same provider pointing to the same database.
Before you deploy MongoDB as your session database consider the impact that it will have on performance.
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="session" connectionString="mongodb://_mongo_server_name_:_port_number_/_session_database_name_" />
-
The
add name
value can besession
orsharedsession
depending on whether you are configuring private or shared session state. -
Configure the connection string so that it points to your session database.
-
Save your changes.
Configure Sitecore
To configure Sitecore to use the private session-state provider for MongoDB:
-
In your site root folder
<sitename>\Website
, open the web.config file and locate thesessionState
section:RequestResponse<sessionState mode="InProc" cookieless="false" timeout="20">
-
Update the
sessionState
section to use the MongoDB provider instead ofInProc
as shown in the following example. Also, change the name attribute value tomongo
:RequestResponse<sessionState mode="Custom" customProvider="mongo" cookieless="false" timeout="20"> <providers> <add name="mongo" type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider, Sitecore.SessionProvider.MongoDB" connectionStringName="session" pollingInterval="2" compression="true" sessionType="private"/> </providers> </sessionState>
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:
|
If you have configured everything correctly, a session database should appear in your list of MongoDB databases after the first web request.