Sitecore Config Layers and ConfigBuilders

Getting rid of transformations, allow the same build to run in any environment.

It has always been a hassle for me to manage web.config transforms, and slow cheetha transformations for config files. It is annoying to have your build servers do multiple builds to essentially have the same code compile with a different set of variables.

It is solved in Octopus Beploy, by having the build agent replacing tokens within the configuration. However a cleaner option was added in .net 4.7.1 .... tadaaa ConfigBuilders.

And while it opens up a whole set of options, like where to save your configuration and secrets, Azure Storage and similar comes to mind. A handy alternative is to use Environment variables, specially for Sitecore implementations, where Environment variables can be set locally for the application pool in the ApplicationHosts.

Luckily microsoft have an example of this in a preview nuget


Setting up the content builders in web.config..

Add config builders to config sections:
<configSections>
 <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
 </configSections>

Add a new section defining your environemnt builder:
<configBuilders>
  <builders>
     <add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
  </builders>
</configBuilders>

Example of the appSettings using the environment builder:
<appSettings configBuilders="Environment">
      <add key="role:define" value="SET env var" />
 <add key="env:define" value="Set env var" />
 <add key="search:define" value="Solr" />
</appSettings>

Sitecore and dev#lang cookie

I observed what seemed to be a bit strange behavior in a Sitecore 7.2 implementation, I reasontly joined. The strange behavior was only in one of my colleague dev environments (it works on my machine – or actually it, did but not on my colleague).

When the site tried to resolve some specific urls, the last part of the url (after the domain), was solved as the context language. This resulting in a cookie named dev#local was set with a value containing the last part of the url (Eg. If the url was www.mydomain.com/om-Godt the value of the dev#local cookie was set to “om-Godt”.



Since the language “om-Godt” didn’t exist, the site redirected to an error page. 


Funny though, because it was not all the time a page was rendered. Anyway, copying a language value into the url (www.mydomain.com/en/contact-us) the site resolved correctly. After clarifying this, it was pretty obvious where to go next. We verified the “languageEmbedding” was set to “Never” in the LinkManager setting. Just to make sure, it was handled consistently in the solution.

<add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" 
addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" 
languageEmbedding="Never" languageLocation="filePath" lowercaseUrls="false" 
shortenUrls="true" useDisplayName="false" />


We located the Languages.AlwasyStripLanguage setting in the web.config file (it was a 7.2 solution) and verified the setting was set to true. We created an include file for the setting and set it to false.


      <!--  LANGUAGES ALWAYS STRIP LANGUAGE
      This setting specifies if the StripLanguage processor in the <preprocessRequest> pipeline will parse and remove languages from
      the URL, even when the languageEmbedding attribute of the linkProvider is set to "never". You should only change this setting 
      to "false" if the default behavior causes problems in your solution.
      Default value: true 
-->
      <setting name="Languages.AlwaysStripLanguage" value="true" />


After that the language was solved correctly though out the solution.

Sitecore Marketing Automation Activity Type not Showing?

Sitecore Marketing Automation Custom Activity type not showing in Marketing Automation Plan?

Ever tried to create a new Custom Acitivity type in Sitecore Marketing Automation. Followed the instructions at https://doc.sitecore.net/developers/xp/marketing-automation/activities/activity-types/index.html? And the activity type you created still doesn’t appear in the Marketing Actions chunk in the Toolbox Area in the right side of the Marketing Automation App?



Going through the documentation several times making sure, you have created everything right?

Well, if you select plugin class (the plugin containing the metadata that the Sitecore Marketing Automation application uses to find and register the activity type configured in the plugin). Make sure the ID not just match your custom Sitecore activity item ID in your plugin decorator property(located under “master:/sitecore/System/Settings/Analytics/Marketing Automation/Activity Types/My Custom Activity Type”), but keep the ID in lower case.


import { Plugin } from '@sitecore/ma-core';
import { SamplePluginActivity } from './SamplePlugin.Activity';
import { SampleSingleItemModuleNgFactory } from './codegen/sample-single-item.module.ngfactory';
import { SampleSingleItemEditorComponent } from './editor/sample-single-item-editor.component';
@Plugin({
   activityDefinitions: [
       {
           // The ID must match the ID of the activity type description definition item in the CMS.
           //BUT REMEMBER TO LOWERCASE()
           id: 'E24EB15B-1B20-45F2-A48F-FA8FD1549DC1'.toLowerCase(),
           activity: SamplePluginActivity,
           editorComponenet: SampleSingleItemEditorComponent,
           editorModuleFactory: SampleSingleItemModuleNgFactory
       }
   ]
})
export default class SamplePlugin {}

Sitecore 9.0.1 - Publishing Target

I’m currently working on an upgrade project – upgrading a Sitecore v 8.1 solution to Sitecore v9.0.1. I’m using Sitecore Update Installation Wizard. Sure, I had some preparations for the upgrade (like making clean Sitecore include config files etc.), but after that, the upgrade it self actually ran quite smoothly – anyway, better than my +13 years of Sitecore implementation would have predicted…

Sitecore v9. have some breaking changes, new ways of doing configurations etc.

One of the new stuff is how to add new Sitecore databases/Publishing Target. Still, you have to create a “Pulishing Target” item in the Sitecore Shell (located at “master:/sitecore/system/publishing targets”). Create a new Item based on the “Publishing Target” template and add the Database ID in the “Target database” field. Add the connectionstring to the “/App_Config/ConnectionString.config” file (name the connectionstring element with the value from the “Target database” field). But the database element in the Sitecore.Config file has changed. Sitecore no longer uses the proxyDataProvider element. Also, you must add settings for the propertystore and the eventqueueprovider

The Sitecore v8 database element in the Sitecore.config file goes from:
 ...
 <databases>
    <database id="publish-target-Name" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
      <param desc="name">$(id)</param>
      <icon>Images/database_web.png</icon>
      <securityEnabled>true</securityEnabled>
      <dataProviders hint="list:AddDataProvider">
        <dataProvider ref="dataProviders/main" param1="$(id)">
          <disableGroup>publishing</disableGroup>
          <prefetch hint="raw:AddPrefetch">
            <sc.include file="/App_Config/Prefetch/Common.config" />
            <sc.include file="/App_Config/Prefetch/Webdb.config" />
          </prefetch>
        </dataProvider>
      </dataProviders>
      <proxiesEnabled>false</proxiesEnabled>
      <proxyDataProvider ref="proxyDataProviders/main" param1="$(id)" />
      <archives hint="raw:AddArchive">
        <archive name="archive" />
        <archive name="recyclebin" />
      </archives>
      <cacheSizes hint="setting">
        <data>100MB</data>
        <items>50MB</items>
        <paths>2500KB</paths>
        <itempaths>50MB</itempaths>
        <standardValues>2500KB</standardValues>
      </cacheSizes>
    </database>
  </databases>


In Sitecore v9.0.1 To:
...
<databases>
    <database id="publish-target-Name" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
      <param desc="name">$(id)</param>
      <icon>Images/database_web.png</icon>
      <securityEnabled>true</securityEnabled>
      <dataProviders hint="list:AddDataProvider">
        <dataProvider ref="dataProviders/main" param1="$(id)">
          <disableGroup>publishing</disableGroup>
          <prefetch hint="raw:AddPrefetch">
            <sc.include file="/App_Config/Prefetch/Common.config" />
            <sc.include file="/App_Config/Prefetch/Webdb.config" />
          </prefetch>
        </dataProvider>
      </dataProviders>
      <PropertyStore ref="PropertyStoreProvider/store[@name='$(id)']" />
      <remoteEvents.EventQueue>
        <obj ref="eventing/eventQueueProvider/eventQueue[@name='$(id)']" />
      </remoteEvents.EventQueue>
      <archives hint="raw:AddArchive">
        <archive name="archive" />
        <archive name="recyclebin" />
      </archives>
      <cacheSizes hint="setting">
        <data>100MB</data>
        <items>50MB</items>
        <paths>2500KB</paths>
        <itempaths>50MB</itempaths>
        <standardValues>2500KB</standardValues>
      </cacheSizes>
    </database>
    </databases>


And add the propertyStoreProvider:
<PropertyStoreProvider>
    <store name="publish-target-Name" prefix="publish-target-Name" getValueWithoutPrefix="true" singleInstance="true" type="Sitecore.Data.Properties.$(database)PropertyStore, Sitecore.Kernel" >
      <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
      <param resolve="true" type="Sitecore.Abstractions.BaseEventManager, Sitecore.Kernel" />
      <param resolve="true" type="Sitecore.Abstractions.BaseCacheManager, Sitecore.Kernel" />
    </store>
  </PropertyStoreProvider>
Add the EventpQueueProvider:
  <eventing>
    <eventQueueProvider>
      <eventQueue name="publish-target-Name" type="Sitecore.Data.Eventing.$(database)EventQueue, Sitecore.Kernel">
        <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
        <param ref="PropertyStoreProvider/store[@name='$(name)']" />
      </eventQueue>
    </eventQueueProvider>
  </eventing>