<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>Andreas Gehrke</title>
      <link>https://agehrke.com</link>
      <description>Software architect and lead developer with more than 20 years of experience building distributed systems.</description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://agehrke.com/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Thu, 28 Apr 2016 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Proposal for Sitecore.Services.Client and Web API in Sitecore</title>
          <pubDate>Thu, 28 Apr 2016 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/proposal-for-sitecore-services-client/</link>
          <guid>https://agehrke.com/blog/proposal-for-sitecore-services-client/</guid>
          <description xml:base="https://agehrke.com/blog/proposal-for-sitecore-services-client/">&lt;p&gt;In this post I&#39;m going to dive into how the infrastructure for Sitecore.Services.Client is implemented and how it overrides many defaults in ASP.NET Web API such as filters, MediaTypeFormatter and controller selection. Lastly I&#39;m going to look at how Sitecore can improve their usage of Web API. &lt;strong&gt;Disclaimer:&lt;/strong&gt; All information are gathered by myself by investigating Sitecore 8.1 Update-2 configuration files and assemblies, which may mean that&#39;s not completely accurate.&lt;/p&gt;
&lt;h3 id=&quot;what-is-sitecore-services-client&quot;&gt;What is Sitecore.Services.Client&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Sitecore.Services.Client provides a service layer on both the server and the client side of Sitecore applications that you use to develop data-driven applications. Sitecore.Services.Client is configurable and extendable, and the framework and the &quot;scaffolding&quot; it gives you help you create the client-server communication in an application in a consistent way. Sitecore.Services.Client uses the ASP.NET Web API as a foundation&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is Sitecore&#39;s own description of Sitecore.Services.Client - taken from &lt;a rel=&quot;external&quot; href=&quot;https://sdn.sitecore.net/upload/sitecore7/75/developer&amp;#x27;s_guide_to_sitecore.services.client_sc75-usletter.pdf&quot;&gt;Developer&#39;s Guide to Sitecore.Services.Client (PDF)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;details-of-infrastructure&quot;&gt;Details of infrastructure&lt;/h2&gt;
&lt;p&gt;Sitecore.Services.Client are setup and configured by use of an &lt;code&gt;initialize&lt;/code&gt; pipeline processor - defined in Sitecore.Services.Client.config. The processor &lt;code&gt;ServicesWebApiInitializer&lt;/code&gt; is very thin, and instead delegates a lot of the configuration to &lt;code&gt;ServicesHttpConfiguration&lt;/code&gt;. What basically happens is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable CORS&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;IHttpControllerSelector&lt;/code&gt; service with &lt;code&gt;NamespaceHttpControllerSelector&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map Web API routes defined in &lt;code&gt;DefaultRouteMapper&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;IFilters&lt;/code&gt; defined in &lt;code&gt;api/services/configuration/filters&lt;/code&gt; configuration to &lt;code&gt;HttpConfiguration.Filters&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Add Sitecore&#39;s BrowserJsonFormatter to &lt;code&gt;HttpConfiguration.Formatters&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;1-enable-cors&quot;&gt;1: Enable CORS&lt;/h3&gt;
&lt;p&gt;Absolutely nothing special here. Sitecore just calls &lt;a rel=&quot;external&quot; href=&quot;https://msdn.microsoft.com/en-us/library/system.web.http.corshttpconfigurationextensions.enablecors(v=vs.118).aspx&quot;&gt;EnableCors() extension method&lt;/a&gt; on HttpConfiguration.&lt;/p&gt;
&lt;h3 id=&quot;2-replacement-of-ihttpcontrollerselector-with-namespacehttpcontrollerselector&quot;&gt;2: Replacement of IHttpControllerSelector with NamespaceHttpControllerSelector&lt;/h3&gt;
&lt;p&gt;Sitecore changes the controller selector with their own class by &lt;em&gt;globally&lt;/em&gt; replacing &lt;code&gt;IHttpControllerSelector&lt;/code&gt; service on &lt;code&gt;HttpConfiguration.Services&lt;/code&gt;. This affects all Web API controllers in entire solution, which can break things in some not so obvious ways for the user/developer. The replacing class extends the default controller selector, appropriately named &lt;a rel=&quot;external&quot; href=&quot;https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/System.Web.Http/Dispatcher/DefaultHttpControllerSelector.cs&quot;&gt;&lt;code&gt;DefaultHttpControllerSelector&lt;/code&gt;&lt;/a&gt;, by implementing grouping or namespacing of controllers based on a &lt;code&gt;NamespaceQualifiedUniqueNameGenerator&lt;/code&gt; which reads namespace from controllers decorated with &lt;code&gt;ServicesControllerAttribute&lt;/code&gt;. This is somewhat like areas for ASP.NET MVC. It works great - most of the time. After upgrading to Sitecore 8.1 all Web API controllers started to return &lt;em&gt;&quot;An error has occurred&quot;&lt;/em&gt; on CD-servers. As you can read in my &lt;a href=&quot;https://agehrke.com/blog/web-api-error-sitecore81-cd-servers/&quot;&gt;blog post about the subject&lt;/a&gt;, the root cause was related to &lt;code&gt;NamespaceHttpControllerSelector&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;3-mapping-of-routes-using-defaultroutemapper&quot;&gt;3: Mapping of routes using DefaultRouteMapper&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;DefaultRouteMapper&lt;/code&gt; class registers a bunch of Web API routes using &lt;a rel=&quot;external&quot; href=&quot;https://msdn.microsoft.com/en-us/library/system.web.http.httproutecollectionextensions.maphttproute(v=vs.118).aspx&quot;&gt;&lt;code&gt;MapHttpRoute()&lt;/code&gt;&lt;/a&gt; - nothing special there. All routes are defined with a prefix, which defaults to &lt;em&gt;sitecore/api/ssc&lt;/em&gt;. Some routes define controller name and optionally action name. But a wildcard route is also defined as &lt;code&gt;{namespace}/{controller}/{id}/{action}&lt;/code&gt;. This is the route requests will use if you follow &lt;a href=&quot;https://agehrke.com/blog/web-api-controller-in-sitecore-8/&quot;&gt;my approach to Web API controllers in Sitecore 8&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;4-add-globally-defined-filters&quot;&gt;4: Add globally defined filters&lt;/h3&gt;
&lt;p&gt;Sitecore adds various Web API filters &lt;em&gt;globally&lt;/em&gt; to &lt;code&gt;HttpConfiguration.Filters&lt;/code&gt; based on configuration element &lt;code&gt;api/services/configuration/filters&lt;/code&gt;. Globally defined filters run for each and every request through Web API. I have &lt;a href=&quot;https://agehrke.com/blog/disable-sitecore-filters-web-api-controllers/&quot; title=&quot;Disable Sitecore filters for Web API controllers&quot;&gt;previously blogged about these filters&lt;/a&gt;, and encouraged Sitecore to use &lt;a rel=&quot;external&quot; href=&quot;http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api#percontrollerconfig&quot;&gt;controller-specific configuration&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;5-custom-mediatypeformatter-browserjsonformatter&quot;&gt;5: Custom MediaTypeFormatter - BrowserJsonFormatter&lt;/h3&gt;
&lt;p&gt;Sitecore adds an &lt;code&gt;BrowserJsonFormatter&lt;/code&gt; &lt;em&gt;globally&lt;/em&gt; via &lt;code&gt;HttpConfiguration.Formatters&lt;/code&gt; which extends the default &lt;code&gt;JsonMediaTypeFormatter&lt;/code&gt;. It basically ensures that you will get JSON back when making requests to Web API endpoints manually through the browser. However the implementation has one flaw - it hardcodes &lt;code&gt;Content-Type&lt;/code&gt; response header to &lt;code&gt;application/json&lt;/code&gt; and removes any charset information set by &lt;code&gt;JsonMediaTypeFormatter&lt;/code&gt;. This may cause your browser to incorrectly interpret any Unicode characters in the response.&lt;/p&gt;
&lt;h2 id=&quot;suggestions-for-sitecore&quot;&gt;Suggestions for Sitecore&lt;/h2&gt;
&lt;p&gt;I believe it&#39;s bad practice for a library/platform to replace or modify default behavior of other libraries/platforms - at least in undocumented ways. Doing so can make it difficult for developers to track down misbehavior or errors in a library that would otherwise run without problems. But this is exactly what Sitecore.Services.Client does by changing default &lt;code&gt;IHttpControllerSelector&lt;/code&gt; and adding filters and MediaTypeFormatters to the global &lt;code&gt;HttpConfiguration&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Bullet 5 can be changed to applying needed changes to a local &lt;code&gt;HttpControllerSettings&lt;/code&gt; using &lt;a rel=&quot;external&quot; href=&quot;http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api#percontrollerconfig&quot;&gt;controller-specific configuration&lt;/a&gt;. Changes and implementation should be fairly straight forward. For filters Sitecore could also make sure of controller-specific configuration, and add an implementation of &lt;code&gt;IFilterProvider&lt;/code&gt; to &lt;code&gt;HttpControllerSettings.Services&lt;/code&gt;. This implementation would then read filters defined in Sitecore&#39;s configuration.&lt;/p&gt;
&lt;p&gt;Changing of &lt;code&gt;IHttpControllerSelector&lt;/code&gt; is however a bit more difficult. We can&#39;t use &lt;code&gt;HttpControllerSettings&lt;/code&gt; as we do not know which controller to select yet. I believe the best place to extend Web API is by creating a custom &lt;a rel=&quot;external&quot; href=&quot;http://www.asp.net/web-api/overview/advanced/http-message-handlers&quot;&gt;&lt;code&gt;HttpMessageHandler&lt;/code&gt;&lt;/a&gt;. By default &lt;code&gt;HttpControllerDispatcher&lt;/code&gt;, an implementation of HttpMessageHandler, is used to dispatch a request to a controller based on &lt;code&gt;HttpControllerDescriptor&lt;/code&gt; returned by &lt;code&gt;IHttpControllerSelector&lt;/code&gt; - see &lt;a rel=&quot;external&quot; href=&quot;https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/System.Web.Http/Dispatcher/HttpControllerDispatcher.cs#L118&quot;&gt;source code of HttpControllerDispatcher&lt;/a&gt;. I believe Sitecore could copy or extend this class and configure it to use their &lt;code&gt;NamespaceHttpControllerSelector&lt;/code&gt;. This new &lt;code&gt;HttpMessageHandler&lt;/code&gt; can be passed to &lt;a rel=&quot;external&quot; href=&quot;https://msdn.microsoft.com/en-us/library/system.web.http.httproutecollectionextensions.maphttproute(v=vs.118).aspx#M:System.Web.Http.HttpRouteCollectionExtensions.MapHttpRoute%28System.Web.Http.HttpRouteCollection,System.String,System.String,System.Object,System.Object,System.Net.Http.HttpMessageHandler%29&quot;&gt;&lt;code&gt;MapHttpRoute()&lt;/code&gt;&lt;/a&gt; when defining routes in &lt;code&gt;DefaultRouteMapper&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This leaves enabling of CORS which should not interfere with controllers that do not have the &lt;code&gt;EnableCorsAttribute&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;All in all I hope Sitecore will change their current practice of modifying default behavior of ASP.NET Web API.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Web API error in Sitecore 8.1 Update-2 on CD-servers</title>
          <pubDate>Wed, 27 Apr 2016 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/web-api-error-sitecore81-cd-servers/</link>
          <guid>https://agehrke.com/blog/web-api-error-sitecore81-cd-servers/</guid>
          <description xml:base="https://agehrke.com/blog/web-api-error-sitecore81-cd-servers/">&lt;p&gt;This post describes a problem with Web API in Sitecore 8.1 Update-2, causing all Web API controllers to return &lt;em&gt;&quot;An error has occurred.&quot;&lt;/em&gt; error message on CD-servers. You can skip to &lt;a href=&quot;https://agehrke.com/blog/web-api-error-sitecore81-cd-servers/#solution&quot;&gt;my temporary solution&lt;/a&gt; at the end, if you experience the same issue.&lt;/p&gt;
&lt;p&gt;I have previously written about Sitecore.Services.Client and use of ServicesControllerAttribute for easy implementation of Web API in a Sitecore solution - without any pipeline and routing configuration. After upgrading to Sitecore 8.1 Update-2, and reapplying the tedious manual work of &lt;a rel=&quot;external&quot; href=&quot;https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/configuring_servers/configure_a_content_delivery_server&quot;&gt;enabling/disabling config files for CD-servers&lt;/a&gt;, I found that all our Web API controllers failed with a &lt;em&gt;An error has occurred&lt;/em&gt; error message. Here&#39;s the full exception message returned by Web API after disabling &lt;code&gt;customErrors&lt;/code&gt; in web.config:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;error-message.json&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;Message&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;An error has occurred.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;ExceptionMessage&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;experienceAnalytics/api/logger&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;ExceptionType&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;System.InvalidOperationException&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;StackTrace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at Sitecore.ExperienceAnalytics.Api.ApiContainer.CreateObject[T](String xpath)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at Sitecore.ExperienceAnalytics.Api.Http.Filters.NotFoundExceptionFilterAttribute..ctor()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.RuntimeTypeHandle.CreateCaInstance(RuntimeType type, IRuntimeMethodInfo ctor)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.InitializeControllerDictionary()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Lazy`1.CreateValue()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Lazy`1.LazyInitValue()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.FindMatchingController(String namespaceName, String controllerName)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage request)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What first caught my eye was that the stack trace contained non of our custom code, and that the error was happening deep inside Sitecore and Web Api. I was hitting a custom controller and not anything related to &lt;em&gt;ExperienceAnalytics&lt;/em&gt;, which the stack trace could indicate at first glance.&lt;/p&gt;
&lt;p&gt;Here&#39;s what I wrote in a ticket to Sitecore Support:&lt;/p&gt;
&lt;p&gt;From the exception stack trace I have narrowed down the issue to &lt;code&gt;Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.InitializeControllerDictionary()&lt;/code&gt;, which instantiates a &lt;code&gt;HttpControllerDescriptor&lt;/code&gt; for each API controller found in &lt;em&gt;any&lt;/em&gt; referenced assembly. Some API controllers in the &lt;code&gt;Sitecore.ExperienceAnalytics.dll&lt;/code&gt; assembly are decorated with &lt;code&gt;Sitecore.ExperienceAnalytics.Api.Http.Filters.NotFoundExceptionFilterAttribute&lt;/code&gt;. This attribute contains a parameterless constructor that is called by internals of ASP.NET Web API. However the constructor calls &lt;code&gt;Sitecore.ExperienceAnalytics.Api.ApiContainer.GetLogger()&lt;/code&gt; which tries to create an object based on what is defined in an &lt;code&gt;experienceAnalytics/api/logger&lt;/code&gt; configuration element. This element does not exist as it&#39;s defined in &lt;code&gt;Sitecore.ExperienceAnalytics.WebAPI.config&lt;/code&gt;, which should be disabled on CD servers.&lt;/p&gt;
&lt;h3 id=&quot;solution&quot;&gt;My (temporary) solution&lt;/h3&gt;
&lt;p&gt;I have resolved the issue by deleting three Sitecore.ExperienceAnalytics assemblies on CD-servers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.Client.dll&lt;/li&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.dll&lt;/li&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.ReAggregation.dll&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This prevents the code in &lt;code&gt;InitializeControllerDictionary()&lt;/code&gt; to find and instantiate the problematic controllers and filters for ExperienceAnalytics.&lt;/p&gt;
&lt;h3 id=&quot;update-may-11-sitecore-documentation-updated&quot;&gt;Update May 11: Sitecore documentation updated&lt;/h3&gt;
&lt;p&gt;On May 11th I received information Sitecore Support that they had updated &lt;a rel=&quot;external&quot; href=&quot;https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/configuring_servers/configure_a_content_delivery_server&quot;&gt;documentation about configuring CD servers&lt;/a&gt;. Now, this article has the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;h3 id=&quot;xanalytics-assembly-files&quot;&gt;xAnalytics assembly files&lt;/h3&gt;
&lt;p&gt;If you have implemented custom code that uses ASP.NET Web API attribute routing, to avoid errors we recommend that you disable the following .dll files in the &lt;code&gt;\Website\bin&lt;/code&gt; folder:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.dll&lt;/li&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.Client.dll&lt;/li&gt;
&lt;li&gt;Sitecore.ExperienceAnalytics.ReAggregation.dll&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
</description>
      </item>
      <item>
          <title>SiteContext.GetWebSiteUrl() - Hidden use of ContentDatabase</title>
          <pubDate>Wed, 09 Mar 2016 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/sitecontext-getwebsiteurl-content-database/</link>
          <guid>https://agehrke.com/blog/sitecontext-getwebsiteurl-content-database/</guid>
          <description xml:base="https://agehrke.com/blog/sitecontext-getwebsiteurl-content-database/">&lt;p&gt;I was recently looking at &lt;a rel=&quot;external&quot; href=&quot;http://www.chrisvandesteeg.nl/2015/11/03/sitecore-composite-components/&quot;&gt;Sitecore composite components&lt;/a&gt; by &lt;a rel=&quot;external&quot; href=&quot;http://twitter.com/csteeg&quot;&gt;Chris van de Steeg&lt;/a&gt;. It&#39;s a great and useful concept which he explains well. I grabbed his implementation on Github to give it a try.&lt;/p&gt;
&lt;p&gt;Unfortunately the code in &lt;a rel=&quot;external&quot; href=&quot;https://github.com/csteeg/BoC.Sitecore.CompositeComponents/blob/master/src/Controllers/CompositeComponentController.cs&quot;&gt;CompositeComponentController&lt;/a&gt; threw a NullReferenceException inside a call to &lt;code&gt;SiteContext.GetWebSiteUrl()&lt;/code&gt;. Having never used that particular method before, I turned to my primary Sitecore documentation tool - the decompiler. Turns out the method calls an overloaded version of it self by passing a &lt;code&gt;Database&lt;/code&gt; as argument - but not just any database, &lt;code&gt;Sitecore.Context.ContentDatabase&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Maybe I&#39;m too much of a Sitecore newbie for asking this, but what is the content database in code running on a CD-server? In my solution it&#39;s &lt;code&gt;null&lt;/code&gt;. Decompiling into the &lt;code&gt;ContentDatabase&lt;/code&gt; property of &lt;code&gt;Sitecore.Context&lt;/code&gt;, I see that you can set a content database on the site definition config using a &lt;code&gt;content&lt;/code&gt; attribute. Should I set it to &lt;em&gt;web&lt;/em&gt; on CD-servers?&lt;/p&gt;
&lt;p&gt;Have you experienced other Sitecore APIs that make hidden use of ContentDatabase?&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Disable Sitecore filters for Web API controllers</title>
          <pubDate>Mon, 08 Feb 2016 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/disable-sitecore-filters-web-api-controllers/</link>
          <guid>https://agehrke.com/blog/disable-sitecore-filters-web-api-controllers/</guid>
          <description xml:base="https://agehrke.com/blog/disable-sitecore-filters-web-api-controllers/">&lt;p&gt;I have previously written about how easy it to implement &lt;a href=&quot;https://agehrke.com/blog/web-api-controller-in-sitecore-8/&quot; title=&quot;Web API controller with async/await in Sitecore 8&quot;&gt;Web API controllers in Sitecore&lt;/a&gt;. However since Sitecore adds a lot of global filters for authorization and security policies - e.g. see &lt;code&gt;sitecore/api/configuration/filters&lt;/code&gt; section in &lt;code&gt;Sitecore.Services.Client.config&lt;/code&gt;. You might want to disable these filters, as they can interfere when building a public accessible API - see the code below. During a debugging session I noticed that a filter from some FXM assembly were also added.&lt;/p&gt;
&lt;p&gt;To be fair, most of Sitecore&#39;s implementations of &lt;code&gt;IFilter/ActionFilterAttribute&lt;/code&gt; that are assigned globally on &lt;code&gt;HttpConfiguration&lt;/code&gt;, does check for presence of &lt;code&gt;ServicesControllerAttribute&lt;/code&gt; and inheritance of &lt;code&gt;ServicesApiController&lt;/code&gt;. This means you might prevent these filters from doing anything by using &lt;code&gt;System.Web.Http.ApiController&lt;/code&gt; as base class for your controllers. I haven&#39;t been though the code for all Sitecore&#39;s filters, so I&#39;m playing it safe, and decorate my ApiControllers with a &lt;code&gt;ClearSitecoreWebApiConfigAttribute&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ApiController.cs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Available at url: /sitecore/api/ssc/example1/andreas/{id}/{action}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Core&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ServicesController&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;example1.andreas&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ClearSitecoreWebApiConfig&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; MyController&lt;/span&gt;&lt;span&gt; :&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ApiController&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;HttpGet&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;	public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; IHttpActionResult&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; MyAction&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;		//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Implement&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;ClearSitecoreWebApiConfigAttribute.cs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Linq&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; YourNamespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Clear Sitecore&amp;#39;s Web API config for a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;see&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; cref&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;ApiController&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;remarks&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Removes &lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;see&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; cref&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;System.Web.Http.Filters.IFilter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;see&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; cref&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;System.Net.Http.Formatting.MediaTypeFormatter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; set by Sitecore.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Note that this means Authorization Filters and Security Policies defined by Sitecore.Services.Client will no longer work for this controller.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    ///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;remarks&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;AttributeUsage&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;AttributeTargets&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Class&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; AllowMultiple&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; false&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Inherited&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; ClearSitecoreWebApiConfigAttribute&lt;/span&gt;&lt;span&gt; :&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Attribute&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Controllers&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;IControllerConfiguration&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Initialize&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Controllers&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;HttpControllerSettings&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; controllerSettings&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Controllers&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;HttpControllerDescriptor&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; controllerDescriptor&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;            //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Remove Sitecore&amp;#39;s Sitecore.Services.Infrastructure.Web.Http.Formatting.BrowserJsonFormatter configured in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;            //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Sitecore.Services.Infrastructure.Sitecore.ApplicationContainer.ResolveServicesWebApiConfiguration().&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; sitecoreFormatter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; controllerSettings&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Formatters&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;FirstOrDefault&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;formatter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; formatter&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;GetType&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Infrastructure&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Formatting&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;BrowserJsonFormatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;sitecoreFormatter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; controllerSettings&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Formatters&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Remove&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;sitecoreFormatter&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;            //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Remove the ConfigurationFilterProvider as this is responsible for providing the globally configured Sitecore filters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; filterProviders&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; controllerSettings&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;GetFilterProviders&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; configurationFilterProvider&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; filterProviders&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;FirstOrDefault&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;provider&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; provider&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;GetType&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Filters&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ConfigurationFilterProvider&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;configurationFilterProvider&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                controllerSettings&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Remove&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Filters&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;IFilterProvider&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; configurationFilterProvider&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I encourage the developers of Sitecore to consider using &lt;a rel=&quot;external&quot; href=&quot;http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api#percontrollerconfig&quot;&gt;controller-specific configuration&lt;/a&gt; instead of loading the global &lt;code&gt;HttpConfiguration&lt;/code&gt; with all kinds of module or feature specific stuff.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Web API controller with async/await in Sitecore 8</title>
          <pubDate>Wed, 05 Aug 2015 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/web-api-controller-in-sitecore-8/</link>
          <guid>https://agehrke.com/blog/web-api-controller-in-sitecore-8/</guid>
          <description xml:base="https://agehrke.com/blog/web-api-controller-in-sitecore-8/">&lt;p&gt;So you want to create Web API controllers in a Sitecore 8 solution? Use &lt;code&gt;Sitecore.Services.Infrastructure.Web.Http.ServicesApiController&lt;/code&gt; and add &lt;code&gt;Sitecore.Services.Core.ServicesControllerAttribute&lt;/code&gt; to namespace your controller. Read &lt;a rel=&quot;external&quot; href=&quot;https://sdn.sitecore.net/upload/sitecore7/75/developer&amp;#x27;s_guide_to_sitecore.services.client_sc75-usletter.pdf&quot;&gt;Developer&#39;s Guide to Sitecore.Services.Client (PDF)&lt;/a&gt; from page 61 and onward. Controllers will be reachable at:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;That&#39;s it. No routing setup, no pipeline fiddling. Quick and easy! Just note that Sitecore does not support dependency injection in the controller - at least out of the box.&lt;/p&gt;
&lt;p&gt;Below is a full example that shows async/await in a Web API controller - note the &lt;code&gt;aspnet:UseTaskFriendlySynchronizationContext&lt;/code&gt; appSetting in Web.config.&lt;/p&gt;
&lt;p&gt;You might also want to check my post on &lt;a href=&quot;https://agehrke.com/blog/disable-sitecore-filters-web-api-controllers/&quot; title=&quot;Disable Sitecore filters for Web API controllers&quot;&gt;disabling of Sitecore Web API filters&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ApiController.cs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Note that name of controller does not matter when using ServicesControllerAttribute like below.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; You can reach the Test() action on url: /sitecore/api/ssc/example1/andreas/1/test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;summary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Core&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ServicesController&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;example1.andreas&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; ApiController&lt;/span&gt;&lt;span&gt; :&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Services&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Infrastructure&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Web&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Http&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ServicesApiController&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;HttpGet&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;	public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Task&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;IHttpActionResult&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Test&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; id&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; database&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Database&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;User&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; language&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Language&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;		//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Emulate async work&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		await&lt;/span&gt;&lt;span&gt; Task&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;500&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; databaseAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Database&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; userAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;User&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; languageAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Context&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Language&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;		return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;new&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			Id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; id&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			DatabaseName&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; database&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			DatebaseNameAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; databaseAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;?&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;?&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			UserAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; userAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;?&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			Language&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; language&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			LanguageAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; languageAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;?&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		}&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Output.json&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;DatabaseName&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;DatebaseNameAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;sitecore&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;admin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;UserAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;sitecore&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;admin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;Language&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;da-DK&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;LanguageAfterAwait&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;da-DK&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Web.config&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;appSettings&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &amp;lt;!--&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Add the following setting for proper flowing HttpContext across awaits &lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;--&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; key&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;aspnet:UseTaskFriendlySynchronizationContext&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; value&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;appSettings&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      </item>
      <item>
          <title>Resize media image stream in Sitecore</title>
          <pubDate>Fri, 20 Feb 2015 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/resize-media-image-stream-in-sitecore/</link>
          <guid>https://agehrke.com/blog/resize-media-image-stream-in-sitecore/</guid>
          <description xml:base="https://agehrke.com/blog/resize-media-image-stream-in-sitecore/">&lt;p&gt;When working with MediaItems in Sitecore you might want to direct access to a stream behind the media item. On the a &lt;code&gt;Sitecore.Data.Items.MediaItem&lt;/code&gt; you can call &lt;code&gt;GetMediaStream()&lt;/code&gt; to accomplish that. It will return a stream to the raw data which might not be ideal if you are working with images. Often you would want a resized image, and fortunately you can use the &lt;code&gt;Sitecore.Resources.Media.ResizeProcessor&lt;/code&gt; pipeline processor.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ResizeImageStream.cs&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; mediaItem&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; GetMediaItemFromSomewhere&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; mediaOptions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; global&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Resources&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Media&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;MediaOptions&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt; MaxWidth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 300&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; pipelineArgs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; global&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Resources&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Media&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;GetMediaStreamPipelineArgs&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; global&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Resources&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Media&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;MediaData&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;mediaItem&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; mediaOptions&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Run resizing pipeline&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; resizeProcessor&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; global&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Sitecore&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Resources&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Media&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;ResizeProcessor&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;resizeProcessor&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Process&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;pipelineArgs&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Copy resized OutputStream to MemoryStream, or use OutputStream.Stream directly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; memoryStream&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;IO&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;MemoryStream&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pipelineArgs&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;OutputStream&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;CopyTo&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;memoryStream&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pipelineArgs&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;OutputStream&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Dispose&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;memoryStream&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;Seek&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; System&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;IO&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;SeekOrigin&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;Begin&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      </item>
      <item>
          <title>Fixing Sitecore Fast Query - querying by field ID</title>
          <pubDate>Mon, 15 Dec 2014 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/fixing-sitecore-fast-query-querying-by-field-id/</link>
          <guid>https://agehrke.com/blog/fixing-sitecore-fast-query-querying-by-field-id/</guid>
          <description xml:base="https://agehrke.com/blog/fixing-sitecore-fast-query-querying-by-field-id/">&lt;p&gt;Sitecore Fast Query is a XPath like query syntax for retrieving and filtering items from the Sitecore database, which uses the database engine to execute queries. This means a Fast Query is directly translated to a SQL query against one of the Sitecore SQL databases. The key tables/views used in the SQL queries are &lt;em&gt;Items&lt;/em&gt; table and &lt;em&gt;Fields&lt;/em&gt; view, which queries &lt;em&gt;VersionedFields&lt;/em&gt;, &lt;em&gt;UnversionedFields&lt;/em&gt;, and &lt;em&gt;SharedFields&lt;/em&gt; tables. TL;DR - Are you only interested in the code to fix Sitecore Fast Query and be able to query by field ID, &lt;a rel=&quot;external&quot; href=&quot;https://gist.github.com/agehrke/17b1e11807e8b37692bd&quot;&gt;see this gist&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;motivation&quot;&gt;Motivation&lt;/h3&gt;
&lt;p&gt;So you might be thinking: why use a Sitecore Fast Query at all? Sitecore has &lt;em&gt;Sitecore Search&lt;/em&gt; based on Lucene or Solr indexes! Well, sometimes you require up-to-date data, and can&#39;t rely on the sometimes stale data in a Lucene index.&lt;/p&gt;
&lt;h3 id=&quot;fast-query-example&quot;&gt;Fast Query example&lt;/h3&gt;
&lt;p&gt;Let&#39;s look at an example of a Sitecore Fast Query, and the SQL generated.&lt;/p&gt;
&lt;p&gt;Fast Query:&lt;/p&gt;
&lt;p&gt;fast://*[@@templateid=&#39;{C29492D2-6F79-463C-A7FB-B318FAB90639}&#39; and @#Postal Code#=&#39;43870&#39;]&lt;/p&gt;
&lt;p&gt;Generated SQL: [sql] exec sp_executesql N&#39;SELECT DISTINCT [i].[ID] [ID], [i].[ParentID] [ParentID] FROM [Items] [i] LEFT OUTER JOIN ( SELECT [Fields].* from [Fields] INNER JOIN [Items] ON [Fields].[FieldID] = [Items].[ID] AND lower([Items].[Name]) = &#39;&#39;postal code&#39;&#39; ) [Fields1] ON [i].[ID] = [Fields1].[ItemId] WHERE (([i].[TemplateID] = @value1) and (coalesce([Fields1].[Value], &#39;&#39;&#39;&#39;) LIKE @value2))&#39;,N&#39;@value1 nvarchar(38),@value2 nvarchar(5)&#39;,@value1=N&#39;{C29492D2-6F79-463C-A7FB-B318FAB90639}&#39;,@value2=N&#39;43870&#39; [/sql]&lt;/p&gt;
&lt;p&gt;The query searches for all items of a specific templateid which has a &lt;em&gt;Postal Code&lt;/em&gt; field with value &#39;43870&#39;. As you can see the SQL query uses a subselect on &lt;em&gt;Items&lt;/em&gt; and &lt;em&gt;Fields&lt;/em&gt; to get the field details for the &lt;em&gt;Postal Code&lt;/em&gt; field. We should be able to eliminate the join on &lt;em&gt;Items&lt;/em&gt; table, if we know the ID of the field we are querying. But how do you specify a field ID instead of name in a Sitecore Fast Query? Turns out no documentation exists - like so many other Sitecore features... So we turn to the best documentation tool for Sitecore, &lt;a href=&quot;https://agehrke.com/blog/sitecore-debugging-dotpeek/&quot; title=&quot;Sitecore debugging with dotPeek&quot;&gt;a decompiler, such as dotPeek&lt;/a&gt;. My colleague Carsten had already asked him self the same question, and had the answer.&lt;/p&gt;
&lt;h3 id=&quot;how-to-query-by-field-id&quot;&gt;How to query by field ID&lt;/h3&gt;
&lt;p&gt;Use &lt;code&gt;@f012901edc1e449b79077eedc19cab81d&lt;/code&gt; as field name. Notice the leading &lt;em&gt;f&lt;/em&gt; followed by a GUID, your field ID. The implementation in &lt;code&gt;Sitecore.Data.DataProviders.Sql.FastQuery.FieldTranslator&lt;/code&gt; expects a field name of 33 characters, including the &lt;em&gt;f&lt;/em&gt;, which means that you can not include dashes in your guid. Tip: Use the &lt;code&gt;Sitecore.Data.ID.ToShortID()&lt;/code&gt; method to convert your field id into the proper format.&lt;/p&gt;
&lt;p&gt;Now, one would expect that the query above could be re-written to:&lt;/p&gt;
&lt;p&gt;fast://*[@@templateid=&#39;{C29492D2-6F79-463C-A7FB-B318FAB90639}&#39; and @f012901edc1e449b79077eedc19cab81d=&#39;43870&#39;]&lt;/p&gt;
&lt;p&gt;Unfortunately this does not work, and throws an error.&lt;/p&gt;
&lt;h3 id=&quot;fixing-querying-by-field-id-take-1&quot;&gt;Fixing querying by field ID - take 1&lt;/h3&gt;
&lt;p&gt;When using the XPath Builder tool in Sitecore and the query above, you get the error: &lt;em&gt;Index (zero based) must be greater than or equal to zero and less than the size of the argument list&lt;/em&gt;. You might recognize the text, it&#39;s the exception message thrown from &lt;code&gt;string.Format&lt;/code&gt;. Running the Fast Query manually through the &lt;code&gt;Sitecore.Data.Database.SelectSingleItem()&lt;/code&gt; method, you will see that exception is thrown deep inside &lt;code&gt;Sitecore.Data.DataProviders.Sql.SqlDataApi&lt;/code&gt; - if I remember correctly. Having a closer look at the implementation of &lt;code&gt;Sitecore.Data.DataProviders.Sql.FastQuery.FieldTranslator&lt;/code&gt; one sees that a &lt;code&gt;IDFieldInfo&lt;/code&gt; class is used to build the field querying part - the part in the SQL subselect above. The implementation of &lt;code&gt;IDFieldInfo&lt;/code&gt; is quite simple, the important part is this line:&lt;/p&gt;
&lt;p&gt;[csharp] context.AddSubquery(context.SqlApi.Format(&quot;(SELECT * FROM {0}Fields{1} WHERE {0}FieldID{1}=&#39;&quot;) + context.SqlApi.FormatRawID(fieldId) + &quot;&#39;)&quot;, &quot;Fields&quot;) [/csharp]&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;fieldId&lt;/code&gt; variable is a &lt;code&gt;Sitecore.Data.ID&lt;/code&gt; instance, and we all know how the string representation of an ID looks: &lt;em&gt;{3db0ff43-3912-4fe0-9f75-9e26e2051a22}&lt;/em&gt;. But hey! Curly brackets have a special meaning in &lt;code&gt;string.Format&lt;/code&gt; and should be escaped using &lt;code&gt;and&lt;/code&gt;. So how does the &lt;code&gt;FormatRawID()&lt;/code&gt; method format an ID? Yup, you guessed it: &lt;code&gt;id.ToString()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So if we can fix the &lt;code&gt;FormatRawID()&lt;/code&gt; method in &lt;code&gt;Sitecore.Data.DataProviders.Sql.SqlDataApi&lt;/code&gt; class, we should have a working Sitecore Fast Query. Fortunately the SqlDataApi class is &lt;em&gt;public abstract&lt;/em&gt; and the method &lt;em&gt;protected virtual&lt;/em&gt; - two minutes later, we have a new implementation of &lt;code&gt;FormatRawID()&lt;/code&gt;. Actually Sitecore has two implementations of the SqlDataApi class, one for SQL Server and one for Oracle. Since we are working with a SQL Server, so we inherit from &lt;code&gt;Sitecore.Data.SqlServer.SqlServerDataApi&lt;/code&gt;. But how do we instruct Sitecore to use our new &lt;code&gt;SqlServerDataApi&lt;/code&gt; implementation? A quick scan through Sitecore&#39;s web.config reveals:&lt;/p&gt;
&lt;p&gt;[xml] &lt;dataApis&gt; &lt;!-- Data api for accessing SQL Server databases. --&gt; &lt;dataApi name=&quot;SqlServer&quot; type=&quot;Sitecore.Data.SqlServer.SqlServerDataApi, Sitecore.Kernel&quot;&gt; &lt;param connectionStringName=&quot;$(1)&quot; /&gt; &lt;/dataApi&gt; &lt;/dataApis&gt; [/xml]&lt;/p&gt;
&lt;p&gt;Wow! This is exactly what we need! So we change the type attribute to point to our new class, and expect to have a working Sitecore Fast Query. But our query still fails, and the debug breakpoint in &lt;code&gt;FormatRawID()&lt;/code&gt; is never reached. Turns out Sitecore doesn&#39;t use the config setting for anything - the setting has the exact same value in the web.config for Oracle.&lt;/p&gt;
&lt;h3 id=&quot;fixing-querying-by-field-id-take-2&quot;&gt;Fixing querying by field ID - take 2&lt;/h3&gt;
&lt;p&gt;Instead you have to replace the entire &lt;code&gt;SqlDataProvider&lt;/code&gt;, in our case the &lt;code&gt;Sitecore.Data.SqlServer.SqlServerDataProvider&lt;/code&gt;. But this class has the following constructor:&lt;/p&gt;
&lt;p&gt;[csharp] public SqlServerDataProvider(string connectionString) : base((SqlDataApi) new SqlServerDataApi(connectionString)) { } [/csharp]&lt;/p&gt;
&lt;p&gt;Wow, hardcoded to &lt;code&gt;SqlServerDataApi&lt;/code&gt;! Great job, Sitecore. So we are stuck with the default &lt;code&gt;SqlServerDataApi&lt;/code&gt;. Instead we must override the &lt;code&gt;Sitecore.Data.DataProviders.Sql.FastQuery.QueryToSqlTranslator&lt;/code&gt; which parses a Fast Query to &lt;em&gt;steps/opcodes&lt;/em&gt; using &lt;code&gt;Sitecore.Data.Query.QueryParser&lt;/code&gt; and translates these to SQL using &lt;code&gt;Sitecore.Data.DataProviders.Sql.FastQuery.IOpcodeTranslator&lt;/code&gt; implementations. The previously mentioned class &lt;code&gt;FieldTranslator&lt;/code&gt; is such an implementation. Below is a reimplementation of &lt;code&gt;FieldTranslator.RenderFieldByGuid&lt;/code&gt; with the only change to use &lt;code&gt;KvIDFieldInfo&lt;/code&gt; instance instead of &lt;code&gt;IDFieldInfo&lt;/code&gt;. &lt;code&gt;KvIDFieldInfo&lt;/code&gt; includes the fix to proper escape the field ID in our Fast Query.&lt;/p&gt;
&lt;p&gt;[csharp] public class KvFieldTranslator : FieldTranslator { protected override string RenderFieldByGuid(Sitecore.Data.ID fieldID, ITranslationContext context) { context.Data[&quot;complex-fields&quot;] = true; var info = context.Fields[fieldID] as IFieldInfo; if (info == null) { info = new KvIDFieldInfo(fieldID, context); context.Fields[fieldID] = info; }&lt;/p&gt;
&lt;p&gt;return this.RenderField(info, context); } }&lt;/p&gt;
&lt;p&gt;public class KvIDFieldInfo : IFieldInfo { public string Alias { get; private set; }&lt;/p&gt;
&lt;p&gt;public KvIDFieldInfo(Sitecore.Data.ID fieldId, ITranslationContext context) { this.Alias = context.AddSubquery(context.SqlApi.Format(&quot;(SELECT {0}ItemId{1}, {0}Value{1} FROM {0}Fields{1} WHERE {0}FieldID{1}=&#39;&quot;) + context.SqlApi.Safe(fieldId.ToGuid().ToString()) + &quot;&#39;)&quot;, &quot;Fields&quot;); } } [/csharp]&lt;/p&gt;
&lt;p&gt;Now we need to use our custom &lt;code&gt;KvFieldTranslator&lt;/code&gt; for query opcodes of type &lt;code&gt;Sitecore.Data.Query.FieldElement&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;[csharp] public class KvQueryToSqlTranslator : Sitecore.Data.DataProviders.Sql.FastQuery.QueryToSqlTranslator { public KvQueryToSqlTranslator(Sitecore.Data.DataProviders.Sql.SqlDataApi api) : base(api) { ((Sitecore.Data.DataProviders.Sql.FastQuery.BasicTranslatorFactory)this._factory).Register(typeof(FieldElement), new KvFieldTranslator()); } } [/csharp]&lt;/p&gt;
&lt;p&gt;And lastly a custom &lt;code&gt;SqlServerDataProvider&lt;/code&gt; which instantiates our &lt;code&gt;KvQueryToSqlTranslator&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;[csharp] public class KvSqlServerDataProvider : Sitecore.Data.SqlServer.SqlServerDataProvider { public KvSqlServerDataProvider(string connectionString) : base(connectionString) { }&lt;/p&gt;
&lt;p&gt;protected override Sitecore.Data.DataProviders.Sql.FastQuery.QueryToSqlTranslator CreateSqlTranslator() { return new KvQueryToSqlTranslator(this.Api); } } [/csharp]&lt;/p&gt;
&lt;p&gt;Instruct Sitecore to use our data provider:&lt;/p&gt;
&lt;p&gt;[xml] &lt;dataProviders&gt; &lt;main type=&quot;Kraftvaerk.KvSqlServerDataProvider, Kraftvaerk&quot;&gt; &lt;param connectionStringName=&quot;$(1)&quot; /&gt; &lt;Name&gt;$(1)&lt;/Name&gt; &lt;/main&gt; &lt;/dataProviders&gt; [/xml]&lt;/p&gt;
&lt;p&gt;Now our Sitecore Fast Query with field ID works as expected, and generates the following SQL query:&lt;/p&gt;
&lt;p&gt;[sql] exec sp_executesql N&#39;SELECT DISTINCT [i].[ID] [ID], [i].[ParentID] [ParentID] FROM [Items] [i] LEFT OUTER JOIN ( SELECT [ItemId], [Value] FROM [Fields] WHERE [FieldID]=&#39;&#39;67e0f992-ae49-4113-8408-e355d5be6b97&#39;&#39; ) [Fields1] ON [i].[ID] = [Fields1].[ItemId] WHERE (([i].[TemplateID] = @value1) and (coalesce([Fields1].[Value], &#39;&#39;&#39;&#39;) LIKE @value2))&#39;,N&#39;@value1 nvarchar(38),@value2 nvarchar(5)&#39;,@value1=N&#39;{C29492D2-6F79-463C-A7FB-B318FAB90639}&#39;,@value2=N&#39;43870&#39; [/sql]&lt;/p&gt;
&lt;p&gt;So our query now only contains a subquery on &lt;em&gt;Fields&lt;/em&gt; view for a fixed field id, which should be faster than the previous query. But there is plenty of room for further improvement. In future post I&#39;ll examine the execution plans for the two queries, and show how to optimize them with a few indexes in the Sitecore SQL database.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Sitecore debugging with dotPeek</title>
          <pubDate>Sun, 16 Nov 2014 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/sitecore-debugging-dotpeek/</link>
          <guid>https://agehrke.com/blog/sitecore-debugging-dotpeek/</guid>
          <description xml:base="https://agehrke.com/blog/sitecore-debugging-dotpeek/">&lt;p&gt;Jetbrains dotPeek tool can act as a symbol server for Visual Studio. Read about &lt;a rel=&quot;external&quot; href=&quot;https://www.jetbrains.com/decompiler/webhelp/Using_product_as_a_Symbol_Server.html&quot;&gt;how to set it up on their excellent webhelp&lt;/a&gt;. Now leave dotPeek running and attach the Visual Studio debugger to your w3wp.exe process, and let dotPeek generate PDB files and source files for your Sitecore solution. It can take dotPeek several minutes to decompile all assemblies. Follow the decompilation process in the &lt;a rel=&quot;external&quot; href=&quot;https://www.jetbrains.com/decompiler/webhelp/Reference__Project_PDB_Generation.html&quot;&gt;Project/PDB Generation Log&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can now debug into Sitecore assemblies which can come in handy when using one of the many less documented features of Sitecore.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>MVC REST services in Umbraco 4</title>
          <pubDate>Wed, 24 Oct 2012 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/mvc-rest-services-in-umbraco-4/</link>
          <guid>https://agehrke.com/blog/mvc-rest-services-in-umbraco-4/</guid>
          <description xml:base="https://agehrke.com/blog/mvc-rest-services-in-umbraco-4/">&lt;p&gt;Create a Global.asax file for your Umbraco project. In the Application_Start method register the MVC routes: [csharp] protected void Application_Start() { RouteTable.Routes.MapRoute(&quot;ServiceRoute&quot;, &quot;Services/{controller}/{action}/{id}&quot;, new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }, new string[] { &quot;Your.Namespace.For.Mvc.Controllers&quot; }); } [/csharp]&lt;/p&gt;
&lt;p&gt;Because Umbraco already contains an empty compiled Global.asax/HttpApplication class in the bin folder, you must delete the &quot;bin/App_global.asax.dll&quot; file. You might &lt;a rel=&quot;external&quot; href=&quot;http://blog.mattbrailsford.com/2010/07/11/registering-an-application-start-event-handler-in-umbraco/&quot;&gt;read other ways&lt;/a&gt; to register Application_Start events in Umbraco. However I never managed to get this to work.&lt;/p&gt;
&lt;p&gt;You also need to instruct Umbraco to ignore URLs for the MVC controllers. In Umbraco&#39;s web.config&#39;s change the &quot;umbracoReservedPaths&quot; app setting:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;appSettings&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; key&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;umbracoReservedPaths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; value&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;~/umbraco,~/install/,~/Services/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;appSettings&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      </item>
      <item>
          <title>Setting Content-Type in an Umbraco /Base service</title>
          <pubDate>Mon, 12 Sep 2011 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/set-content-type-in-umbraco-base-service/</link>
          <guid>https://agehrke.com/blog/set-content-type-in-umbraco-base-service/</guid>
          <description xml:base="https://agehrke.com/blog/set-content-type-in-umbraco-base-service/">&lt;p&gt;The &lt;a rel=&quot;external&quot; href=&quot;http://our.umbraco.org/wiki/reference/umbraco-base&quot;&gt;Umbraco /Base system&lt;/a&gt; is great for creating simple REST-like services. You can use the RestExtensionMethod attribute to instruct Umbraco to return your response as XML or not. But what is “not”? Apparently it means set Response.ContentType to “text/html”. But what if the returned data should be sent using a different mime type? Setting the ContentType manually like&lt;/p&gt;
&lt;p&gt;[csharp] HttpContext.Current.Response.ContentType = &quot;application/json&quot; [/csharp]&lt;/p&gt;
&lt;p&gt;will not do the trick. Umbraco /Base will override it with “text/html” if you are returning a string from your service method.&lt;/p&gt;
&lt;p&gt;What you need to do is to change your method return signature to “void” and write your data directly to the HttpResponse, like: [csharp] HttpContext.Current.Response.ContentType = &quot;application/json&quot;; HttpContext.Current.Response.Write(stringWriter.ToString()); [/csharp]&lt;/p&gt;
&lt;p&gt;Umbraco will not override the content type for “void”-methods. Below is a full example.&lt;/p&gt;
&lt;p&gt;[csharp] [RestExtension(&quot;Member&quot;)] public class MemberService { [RestExtensionMethod(returnXml = false, allowAll = true)] public static void Json() { var json = &quot;{ \&quot;firstName\&quot;: \&quot;John\&quot;, \&quot;lastName\&quot;: \&quot;Smith\&quot;, \&quot;age\&quot;: 25 }&quot;;&lt;/p&gt;
&lt;p&gt;// Write response and set content type HttpContext.Current.Response.ContentType = &quot;application/json&quot;; HttpContext.Current.Response.Write(json); } } [/csharp]&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Nested Set in Propel 1.3</title>
          <pubDate>Sun, 19 Apr 2009 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://agehrke.com/blog/nested-set-in-propel-13/</link>
          <guid>https://agehrke.com/blog/nested-set-in-propel-13/</guid>
          <description xml:base="https://agehrke.com/blog/nested-set-in-propel-13/">&lt;p&gt;I&#39;m currently working on a &lt;a rel=&quot;external&quot; href=&quot;http://www.symfony-project.org/&quot;&gt;Symfony&lt;/a&gt; project with a lot of &lt;a rel=&quot;external&quot; href=&quot;http://dev.mysql.com/tech-resources/articles/hierarchical-data.html&quot;&gt;hierarchical data&lt;/a&gt;. For this I have taken advance of the new &lt;a rel=&quot;external&quot; href=&quot;http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/Tree/NestedSet&quot;&gt;Nested Set implementation in Propel 1.3&lt;/a&gt;. Even though some initial research on Google showed a few people complaining about Propels implementation, I decided to give it a try. My schema.yml&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;eam&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;  _&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;attributes&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;    t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;reeMode&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; N&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;estedSet&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;  i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;d&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;    c&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ompany_id&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ype&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;nteger&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;reeScopeKey&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;    n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ame&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ype&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; V&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;ARCHAR&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ize&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 128&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;equired&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;    l&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ft&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ype&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;nteger&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;equired&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      d&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;efault&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;estedSetLeftKey&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;gt&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      t&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;ype&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;nteger&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;equired&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      d&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;efault&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;      n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#22863A, #85E89D);&quot;&gt;estedSetRightKey&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Currently the only problem I have had is when I need to reassign a new node as root node. My first thought was to make the new node root and add the old root node as child, but Propel doesn&#39;t like that and messes up the left-right values. What I have done is to insert the new node as child of the root node and then swap left-right values, like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; Team&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; TeamPeer&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;retrieveRoot&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;scopeId&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;insertAsFirstChildOf&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Swap left-right values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;rootRight&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getRightValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;setLeftValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getLeftValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;root&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;setRightValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getRightValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Make node root&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;setLeftValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;node&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;setRightValue&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;rootRight&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;display-tree-using-recursiveiteratoriterator&quot;&gt;Display tree using RecursiveIteratorIterator&lt;/h3&gt;
&lt;p&gt;I retrieve the tree with the static peer method &lt;code&gt;retrieveTree()&lt;/code&gt; and display it using the &lt;a rel=&quot;external&quot; href=&quot;http://www.php.net/~helly/php/ext/spl/classRecursiveIteratorIterator.html&quot;&gt;RecursiveIteratorIterator&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;tree&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; TeamPeer&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;retrieveTree&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;scopeId&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;it&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; RecursiveIteratorIterator&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;tree&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; RecursiveIteratorIterator&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;SELF&lt;/span&gt;&lt;span&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;_FIRST&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;foreach&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;it&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; as&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; echo&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However I wanted to print the items as an indented &quot;list&quot; in a dropdown box. For this I extended the &lt;code&gt;RecursiveIteratorIterator&lt;/code&gt; class and implemented its &lt;code&gt;beginChildren()&lt;/code&gt; and &lt;code&gt;endChildren()&lt;/code&gt; methods.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; MyIndentRecursiveIteratorIterator&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; RecursiveIteratorIterator&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  private&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;indent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  private&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;indentStr&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;amp;nbsp;&amp;amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; getIndent&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;indent&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; beginChildren&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;indent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;_repeat&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;indentStr&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getDepth&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; endChildren&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;    $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;indent&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;_repeat&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;indentStr&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; $&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getDepth&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;tree&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; TeamPeer&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;retrieveTree&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;scopeId&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;it&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; MyIndentRecursiveIteratorIterator&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;tree&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; MyIndentRecursiveIteratorIterator&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;SELF&lt;/span&gt;&lt;span&gt;\&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;_FIRST&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;foreach&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;it&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; as&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; echo&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;it&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;getIndent&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; .&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;item&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which produces something like below which can be used in a dropdown or similar.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Root&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Child 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Child 1.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Child 1.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Child 2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      </item>
    </channel>
</rss>
