Platform Administration and Architecture

Walkthrough: Configuring a shared session state database using the Redis provider

Abstract

How to use the SQL service provider as your private session state store.

A contact can make multiple visits to a website from different devices or browser sessions at the same time. With shared session-state the session state database collects all the data that can be shared across these multiple sessions. This includes, for example, data related to contacts and devices. This data is still private to the contact but it is accessible from all current sessions made by the same contact.

You must always configure shared session state on content delivery servers, regardless of whether you have a single content delivery (CD) server, multiple CD servers, or a clustered environment.

Note

Shared session state is not supported on content management (CM) servers.

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 must be able to invoke the SessionEnd event via SessionStateItemExpireCallback.

Note

The standard OutOfProcSessionStateStore that ships with ASP.NET does not support the SessionEnd event and therefore cannot be used with shared session state.

This walkthrough describes how to use Redis as your shared session state store using the Sitecore ASP.NET Session State Store Provider for Redis. It describes how to:

Note

If you are using a Redis session provider, all content delivery servers must use the same provider pointing to the same database.

Deploy a shared Redis session database

The Sitecore ASP.NET session state store provider for Redis enables you to use Redis as your session state store. The provider supports the SessionEnd event, which the xDB needs to track website visits.

To deploy a Redis session database:

  1. Choose between Azure Redis or Redis on premise. You can provision Azure Redis by using the instructions on the Microsoft Azure website or with Azure PowerShell.

  2. Go to the <sitename>\App_Config folder, open the ConnectionStrings.config file, and add the following connection string:

    <add name="sharedSession" connectionString="_host_:_port_number _" />
  3. Configure the connection string so that it points to your session database.

  4. Save your changes.

Configure Sitecore

Note

Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during run time.Use a patch file to customize the Sitecore configuration

The default shared-session store uses the in process provider which stores data in memory and is implemented in the internal ASP.NET class InProcSessionStateStore:

<sharedSessionState defaultProvider="inProc">
    <providers>
    <clear/>
    <add name="inProc"
      type="System.Web.SessionState.InProcSessionStateStore"
      />
    </providers>

To configure Sitecore to instead use the shared session state provider for Redis you must:

  1. In your website root folder, navigate to the App_Config\Include\Sitecore\Marketing.Tracking folder.

  2. Open the Sitecore.Analytics.Tracking.Config file.

  3. Locate the line where you can define the default shared session state provider using the following path: sitecore/tracking/sharedSessionState.

  4. Change the defaultProvider from inProc to redis. Also, change the name attribute value to redis.

    <sharedSessionState
          defaultProvider="redis">
        <providers>
            <clear/>
            <add name="redis"
                type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,Sitecore.SessionProvider.Sql"
                connectionStringName="sharedsession"
                pollingInterval="2"
                compression="true"
                sessionType="shared"/>
        </providers>

Adjust the Redis provider settings

Use the Redis provider settings reference to configure your session state.

If you have configured everything correctly, session records should appear in your Redis session database after the first web request.