1

I am trying to implement a website with shared session functionality with ARR affinity cookie disabled. The logged in user should be able to browse the website even though the request is served from a difference CD instance than the one user logged in. What is the best approach to store the user data and roles in session to implement this. We are using XM scaled architecture.

I have already updated the sessionType to Shared in my Sitecore instance but unfortunately I am not able to share the session data between servers.

<sessionState mode="Custom" customProvider="mssql" cookieless="false" timeout="20">
   <providers>
      <add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" connectionStringName="sharedSession"
          pollingInterval="2" compression="true" sessionType="shared"/>
  </providers>
</sessionState>
2
  • @MarekMusielak: What I was confused it I have an XM instance and tracking config doesn't exists. Right now, I have added the config as a patch file with only the part where it requires to define shared session state and seems like it working Jul 31, 2023 at 8:39

1 Answer 1

1

Sitecore has two session types: private and shared. If you CD server is scaled out to multiple instances and you don't use sticky session (ARR affinity cookie) then both session types should use an external session storage.

Here is an example for SQL session provider:

  1. For private session modify your web.config file to use a custom provider:
<sessionState mode="Custom" customProvider="mssql" cookieless="false" timeout="20">
  <providers>
    <add name="mssql" 
        type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,
        Sitecore.SessionProvider.Sql" 
        connectionStringName="sharedsession" 
        pollingInterval="2" 
        compression="true" 
        sessionType="private"/>
  </providers>
</sessionState>
  1. For shared session create a patch file for for the config Sitecore.Analytics.Tracking.Config and modify the section sitecore/tracking/sharedSessionState:
<sharedSessionState defaultProvider="mssql">
    <providers>
        <clear/>
        <add name="mssql"
            type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,Sitecore.SessionProvider.Sql"
            connectionStringName="sharedsession"
            pollingInterval="2"
            compression="true"
            sessionType="shared"/>
    </providers>
</sharedSessionState>

Both session types can use the same connection string. The database is able to distinguish between different session types.

You can find more details about session storage and configuration examples for SQL and Redis providers in Sitecore documentation here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.