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 .
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…
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>
<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.
|






Comments
Post a Comment