Skip to main content

Sitecore Session State and the MSSQL | OutProc Session in Sitecore


In this blog, I would like to explain OutProc session state in MSSQL server. It cover below points.

1)   Inproc and OutProc Session state management
2)   Shared and Private Session state
3)   How to configure OutProc session State  
4)   When to use OutProc
5)   Advantage of using OutProc
6)   Troubleshoot the issue

1.     What is Session State: 
In ASP.NET session is a state that is used to store and retrieve values of a user.
It helps to identify requests from the same browser during a time period (session). It is used to store value for the particular time session. By default, ASP.NET session state is enabled for all ASP.NET applications. 

     In Sitecore , As a visitor browses around your site, information about that visitor and their interaction is stored in session. When the session ends, this information is flushed to the MSSQL - but for the duration of an interaction, session is solely responsible for storing valuable information about a visitor’s actions on your website. This reduces the number of calls to the collection database, but it means that session management should be as robust as possible.
There is nothing proprietary about session management in Sitecore - it is all built on standard ASP.NET session state.

2.     InProc vs OutProc session state management

InProc and OutProc session management is not specific to Sitecore. InProc is short for ‘In Process’, and means that all session data (both private and shared) is managed in memory. OutProc, conversely, means that session data is stored somewhere else - it might be written to disk as the user browses around your site.
In Sitecore’s case, there are two custom OutProc session providers; one for MongoDB and one for SQL.
A default installation of Sitecore uses InProc session management for both shared and private session data.

3.     Shared vs Private session state
The MSSQL stores two kinds of session information - shared and private .

Private session: Contains information about contact visit information, such as pages viewed, goals converted, or campaigns triggered. Private session state is private to the browser accessing the website.
If a contact accesses a website simultaneously from their desktop and mobile phone, each device will have its own private session state.
Shared  Session : Contains information that can be shared across multiple active sessions. This includes any contact or device information that has been loaded into the tracker at the start of the session.
Shared session state has a read-only copy of a contact’s data; contacts are not locked whilst a session is ongoing. If you need to update a contact with data from an active session, use the xConnect Client API.
Shared session state is not supported on Content Management (CM) servers.

4.     When to use OutProc Session
·         As soon as you scale to multiple CDs within a cluster, you must use OutProc session management for both private and shared session data. This is because shared session data needs to be available to all sessions for a single contact. This is done by storing shared session data in an OutProc session state database.
·         You must always configure shared session state on content delivery (CD) servers, regardless of whether you have a single CD server, multiple CD servers, or a clustered environment.
·         If there is only one CD instance then you may use InProc
·         Content Management (CM) servers do not support using an external session state database. On CM servers you can only use in process session state.

5.     Type of state provider supported by Sitecore
Below are list of providers that is supported by Sitecore. There is no officially supported data that suggests one is faster than the other, although you should always perform your own tests.
o    Private session state database using the MongoDB provider
o    Private session state database using the SQL Server provider
o    Private session state database using the Redis provider
o    Shared session state database using the MongoDB provider
o    Shared session state database using the SQL Server provider
o    Shared session state database using the Redis provider

6.     Advantages of OutProc Session State
OutProc session state is never going to be as fast as InProc session state. However, there are a number of advantages that start to pay off as you scale beyond 10 CD instances.
·         You trade some speed for increased reliability. You can share information across concurrent sessions on multiple devices
·         No need for sticky sessions (sticky sessions may result in uneven splits of traffic across load-balanced CDs)
·          Imagine that you are using InProc session management - everything is stored in memory. If anything goes awry in your content delivery environment (for example, one out of three load-balanced instances goes down), visitors are at risk of losing their entire session. By contrast, if you are using OutProc session management, their session is maintained in a database - the information about that session is not lost.

7.     Configuring OutProc session state database using SQL
A)   Deploy a SQL Server session database
          Note: You can find the file (MDF and LDF) in the Databases folder in the root of the Sitecore zip version of downloaded file.
     

Attach above file in SQL Server as below.
·         Start Microsoft SQL Server Management Studio 2016 or later.
·         Connect to the server node that you want to install the Session database on.
·         Expand the server node, right-click Databases, and then click Attach…

·         Select MDF and LDF file and attach it

B)   Configure Sitecore Config File
1)      Open Connect string and add below connection (Change credentials accordingly) .
File Path : \Website\App_Config\ConnectionStrings.config

Private Session:
<add name="session" connectionString="user id=sa; password=Admin@123; Data Source=LT096577\SQLENTERPRISE17; Database=Sitecore_Sitecore.Sessions" />
Shared Session:
<add name="sharedsession" connectionString="user id=sa; password=Admin@123; Data Source=LT096577\SQLENTERPRISE17; Database=Sitecore_Sitecore.Sessions" />
Note : Comment if there is any connection with same name related to mongo DB.

2)      Open Web.config and comment earlier sessionState section and add another section as below screen shot.
File Path : \Website\Web.config

<sessionState mode="Custom" customProvider="mssql" cookieless="false" timeout="20">
                                  <providers>
                                                <add name="mssql"
                                                                type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,
                                                                Sitecore.SessionProvider.Sql"
                                                                connectionStringName="session"
                                                                pollingInterval="2"
                                                                compression="true"
                                                                sessionType="private"/>
                                  </providers>
    </sessionState>


Shared Session:
3)      Open sharedstate file and do entry as below.
Path : \Website\App_Config\Include\Sitecore.Analytics.Tracking.Config

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

Add Below Config:
<sharedSessionState>
          <patch:attribute name="defaultProvider">mssql</patch:attribute>
                 <providers>
                    <add  name="mssql"            type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,Sitecore.SessionProvider.Sql"
                                   connectionStringName="sharedsession"
                                    pollingInterval="2"
                                    compression="true"
                                   sessionType="shared" />
                   </providers>
              </sharedSessionState>




8.     Troubleshoot
·         Post above configuration browse the site and open database and execute a query in session database to see session entry. If data is being, capture it means session configuration is done correctly.



Note : If you are using login functionalities or some class object are storing in session then you must serialize and desterilize that particular object in backend.


using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Feature.Service.Models
{
[Serializable]
public class ApplicantFeeDetailModel
{
public string mission { get; set; }
public string country { get; set; }
public string center { get; set; }
public string loginUser { get; set; }
public string urn { get; set; }
}
}


Comments

Popular posts from this blog

Sitecore Publishing target and Solr Configuration

Creating a new publishing target is very helpful if your Sitecore environment is setup in multiple content delivery servers. We can publish data from Master database to one or more publishing target databases. Main thing to notice here is Master database contains all versions of any content or assets while publishing target database contains single latest version for each language.      This post aims to provide systematic instructions to set up publishing target. It comprises of a target database (where the content will be published) and publishing target definition item in master database that points to that target database.             Post creation of publishing target need to take care of Solr configuration. This post cove master slave Solr configuration and onPublishEndAsync strategy. We are using 1 Solr Master instance and 6 Slave instance (2-EU, 2-Ap, 2- NA).     1   So...

Setup Sitecore Habitat v9.0 project in simple way

In this article , I would describe how to setup the Sitecore habitat V9.0 project with Sitecore Experience Platform 9.0 rev in very simple way. I used below system configuration to setup this project: 1. Windows 10 (32/64-bit) 2. IIS 10.0 3. .NET Framework 4.6.2 4. Microsoft Visual Studio 2017 5. Microsoft SQL Server 2017 6. Solr 6.6.2 7. Microsoft PowerShell® version 5.0 8. Web Platform Installer 5.0. 9. Web Deploy 3.6 for Hosting Servers 10. Node-v8.9.4-x64 Follow below steps to setup the project. A).   Habitat require Sitecore instance. Setup the clean Sitecore 9.0 instance. Ex : http://demo.local.com , Directory location : C:\inetpub\wwwroot\demo.local.com   For more info visit -   https://dev.sitecore.net/ B). Download the Habitat V9.0 project from Github site :  https://github.com/Sitecore/Habitat/     Note  :  When you download the packages, it is possible that the .ZIP packages are marked as blocke...

Web Deploy setup and configuration with Sitecore

Web Deploy empowers Visual Studio and WebMatrix to help developers streamline the deployment of Web applications to Microsoft IIS Web servers or to Microsoft Azure Websites. In addition, integration with Web Platform Installer allows developers to simply and easily install community webapplications.   This post describe the installation of Web Deploy and Configuration with Sitecore instance.  This post will be very useful if you want to sync your Sitecore media items with all of the CD's environment (Distributed environment) . In one of my previous project, I was keeping all the media items in file system and synchronizing all the files from CM to Cd's server. This solution is tested with 1 CMS and 6 CD's server (2-EU, 2- NA, 2- AP) with more than 5 Lakh files.  1.       Software Pre-requisites           a.       OS – Window 7/ Windows Server 2008 R2 Enterprise       ...