0

We have a custom session state applied only on the content delivery server. so we created a patch configuration for web.config.xdt and included that line

<system.web >
        
        <sessionState xdt:Transform="Replace" mode="Custom" cookieless="false" cookieSameSite="None" timeout="20"
     sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager, Sitecore.Kernel" customProvider="redis">
            <providers>
                <add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" sessionType="Standard"
                  connectionStringName="session" pollingEnabled="true" pollingInterval="60" pollingMaxExpiredSessionsPerSecond="0" pollingMaxInstances="1"
                  compression="true"/>
                <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" applicationName="private"
                  connectionString="redis.sessions" pollingInterval="60" compression="true"/>
            </providers>
        </sessionState>
    </system.web>

But this line should work on CD only not for CM.

How to add this config only for Content Delivery.

I had tried below method but this shows error

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"  xmlns:search="http://www.sitecore.net/xmlconfig/search/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <system.web >
            
            <sessionState role:require="ContentDelivery"  xdt:Transform="Replace" mode="Custom" cookieless="false" cookieSameSite="None" timeout="20"
         sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager, Sitecore.Kernel" customProvider="redis">
                <providers>
                    <add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" sessionType="Standard"
                      connectionStringName="session" pollingEnabled="true" pollingInterval="60" pollingMaxExpiredSessionsPerSecond="0" pollingMaxInstances="1"
                      compression="true"/>
                    <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" applicationName="private"
                      connectionString="redis.sessions" pollingInterval="60" compression="true"/>
                </providers>
            </sessionState>
        </system.web>
    </configuration>

3 Answers 3

1

XDT is just an XML file with a set of rules of what and how to transform within web.comfig. We may use them in cases when we need to somehow transform web.config outside of <sitecore> node of configuration so that we can't rely on config paths that only apply within the <sitecore> node. XDT structure corresponds to the structure of target web.config file with additional commands coming from XML-Document-Transform XML namespace.

Configuration transform relies on msbuild to do this job. But instead of Debug, Release or Clean targets, it uses a target called ApplyTransform It accepts numerous parameters, among those we have XDT file to transform, target folder, target configuration file to be transformed and few other parameters.

Using this xdt file sets up the web.config for CD servers, regular web.config file is set up for CM servers. Applying transform through VSTS using XDT Transform task before CD App Service install.

So in your Web.CD.config you need to replace the config.

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"  xmlns:search="http://www.sitecore.net/xmlconfig/search/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <system.web >
            <sessionState  xdt:Transform="Replace" mode="Custom" cookieless="false" cookieSameSite="None" timeout="20"
         sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager, Sitecore.Kernel" customProvider="redis">
                <providers>
                    <add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" sessionType="Standard"
                      connectionStringName="session" pollingEnabled="true" pollingInterval="60" pollingMaxExpiredSessionsPerSecond="0" pollingMaxInstances="1"
                      compression="true"/>
                    <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" applicationName="private"
                      connectionString="redis.sessions" pollingInterval="60" compression="true"/>
                </providers>
            </sessionState>
        </system.web>
    </configuration>

Refer to these links for more details.

https://doc.sitecore.com/xp/en/developers/101/developer-tools/applying-configuration-transforms.html

https://learn.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110)

Hope it helps!

0

The role based configuration that you are referring to in your question is specifically for Sitecore configuration patch files, which you should use to apply changes to the settings in Sitecore.config file.

Example:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"  xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore role:require="ContentManagement">
    <commands>
        ... some command ...
    </commands>
  </sitecore>
</configuration>

This approach cannot be used control which settings are applied within the web.config file. Instead you must perform a web transform during your deployment.

An example of this might look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <sessionState xdt:Locator="Match(sessionIDManagerType)" xdt:Transform="Replace" sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager, Sitecore.Kernel" mode="Custom" cookieless="false" cookieSameSite="None" timeout="20"  customProvider="redis">
            <providers>
                <add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" sessionType="Standard"
                  connectionStringName="session" pollingEnabled="true" pollingInterval="60" pollingMaxExpiredSessionsPerSecond="0" pollingMaxInstances="1"
                  compression="true"/>
                <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" applicationName="private"
                  connectionString="redis.sessions" pollingInterval="60" compression="true"/>
            </providers>
        </sessionState>
    </system.web>
</configuration>
-1

You can only patch and apply role based transformation on Sitecore related configuration. Sytem.web is asp.net configuration tag. It's not possible to do that on them.

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.