Archive of ‘Sitecore’ category

Sitecore MVC & Controller Dependency Injection

If you are planning on using DI on your Sitecore 7.2 and later projects, you should be aware that Sitecore has itself started using MVC in some of it’s features. For example, if on an image field you click “Browse”, then “Upload”, this diaglog window will call the URL /api/sitecore/Media/Upload?sc_database=master which is an MVC route.

The issue is, if you have set the Controller Factory of your application to your own (this was done when using a Castle Windsor implementation) then you need to ensure you have registered the instances of IController within the Sitecore DLLs as well as your own. The DLLs you need to register are Sitecore.Speak.ClientSitecore.Mvc and Sitecore.Mvc.DeviceSimulator. For example, in Castle Windsor you would need to add something like the following to your Installer which registers your controllers:

For further reading, look at Sitecore support ticket #429145

Cross-site linking in Sitecore

In a Sitecore instance that contains multiple sites, you may have found that links between different sites can result in incorrect URLs.
For example, suppose we have the following Sitecore structure:

  • Sitecore
    • Site A (
      • Page A
    • Site B (
      • Page B

Typically, a link from anywhere on Site A to Page B might result in a URL like “”, rather than the expected “”.

There are a number of things you need to get right in order for this to work properly:

  • The SiteResolving property needs to be set to true on the UrlOptions when calling LinkProvider.GetItemUrl().
    There is a bug in that the Sitecore config setting (Rendering.SiteResolving) is never used to set this property automatically. This can be easily fixed by extending the LinkProvider with a few lines of code.
  • Site definitions must have both hostName and targetHostName attributes set in order for site resolving to work (even if the sites in question all use the same hostnames)

If you want language to be preserved correctly across cross-site links then also:

  • The Rendering.SiteResolvingMatchCurrentLanguage setting must be set to true
  • The casing of the language names must be the same between the definitions in the Sitecore tree and the language attributes on the site site definitions, as a case-sensitive match is performed.

Some relevant articles:

Logging to a Database with Log4Net

If you need to log to a database instead of a text file, you can use Log4Net to do it by just changing some config:

If you want to only log a small number of things to the database (but still log everything else to the existing log), then instead of adding the sql adonet appender to the main root logger in the config, create a new logger node and add the sql ado appender to that. Eg:

<logger name=”PublishLog” additivity=”false”>
<level value=”INFO”/>
<appender-ref ref=”ADONetAppender_PublishedItems”/>

Then when logging, explicitly use this logger using the Sitecore Logger Factory. Eg: “Sitecore.Diagnostics.LoggerFactory.GetLogger(“PublishLog”)”

Minq and Autofac – quick setup guide

Its really simple to get these setup together. Once you have your Sitecore MVC project up and running:

  1. Install Autofac from Nuget
  2. Install Autofac ASP.NET MVC 5 Integration (note, select the appropriate version you require)
  3. Create a new intializer class (see below)
  4. Update the AssemblyInfo and add: [assembly: PreApplicationStartMethod(
    typeof(###.Initialization.Initializer), “Initialize”)]

    1. See for more info on this approach. It avoids needing to update global.asax. This tip was taken from
  5. Update the config as per
  6. Enjoy DI into your controllers

Sitecore language url embedding

There is a new setting in 6.6 that changes the behaviour of languageEmbedding=never in the linkManager code:

This was causing issues post upgrade since we relied on the presence of /en to define different site entries.

Count versions of a Sitecore item

A quick sql script can find any big offenders:

Count items in a Sitecore folder

A quick sql script can find any big offenders:

Sitecore tree performance from IIS logs

If you want to find out average load times for eg how long nodes take to load use the following iis log query and then filter the data in excel:

See IIS Log parser for how to run these queries.