2

This is not exactly a problem, more of an irritating itch... I have replaced the InitializeGlobalFilters with a patchfile called InitializeGlobalFilters.config:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc">
          <patch:attribute name="type">Framework.Pipelines.Filters.InitializeGlobalFilters, DD.Framework</patch:attribute>
        </processor>
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

And this works, it patches the config, but when I look at ShowConfig.aspx, it lists the patch source as the original patch file from sitecore, not my patch file:

<processor patch:source="Sitecore.Mvc.config" type="Framework.Pipelines.Filters.InitializeGlobalFilters, Framework" />

Does this matter? How do I get it to show my patch file as the patch:source?

1
  • Is your InitializeGlobalFilters.config in the route of the Include folder, the same level as the Sitecore.Mvc.Config?
    – Richard Seal
    Feb 15, 2017 at 18:37

3 Answers 3

4

If the configurator patches an original config from a patch config, Patch source equals that first patch config. If a second configuration comes around that patches the same line, the Configurator doesn't record it. Annoying as hell.

In the XmlPatchHelper Class, there's a method called AssignSource:

protected virtual void AssignSource(XmlNode target, object source, XmlPatchNamespaces ns)
{
  Assert.ArgumentNotNull((object) target, "target");
  Assert.ArgumentNotNull(source, "source");
  Assert.ArgumentNotNull((object) ns, "ns");
  IXmlSource xmlSource = source as IXmlSource;
  if (xmlSource == null)
    return;
  string sourceName = xmlSource.SourceName;
  if (string.IsNullOrEmpty(sourceName))
    return;
  Assert.IsNotNull((object) target.OwnerDocument, "target.OwnerDocument");
  string prefix = target.OwnerDocument.GetPrefixOfNamespace(ns.PatchNamespace);
  if (string.IsNullOrEmpty(prefix))
  {
    prefix = "patch";
    XmlNode documentElement = (XmlNode) target.OwnerDocument.DocumentElement;
    XmlAttribute attribute = target.OwnerDocument.CreateAttribute("xmlns:" + prefix);
    attribute.Value = ns.PatchNamespace;
    Assert.IsNotNull((object) documentElement, "rootElement");
    Assert.IsNotNull((object) documentElement.Attributes, "rootElement.Attributes");
    documentElement.Attributes.Append(attribute);
  }
  Assert.IsNotNull((object) target.Attributes, "target.Attributes");
  XmlAttribute attribute1 = target.Attributes["source", ns.PatchNamespace];
  if (attribute1 == null)
  {
    attribute1 = target.OwnerDocument.CreateAttribute(prefix, "source", ns.PatchNamespace);
    target.Attributes.Append(attribute1);
  }
  attribute1.Value = sourceName;
}

The variable attribute1 is the important one. If the patcher comes across a node element that it has ALREADY patched, attribute1 won't return null, therefore, uses the previously assigned source.

1
  • This is the why. And is what I thought was happening. Feb 15, 2017 at 20:18
0

It looks like its just the order that Sitecore is processing the include files. Your file InitializeGlobalFilters.config will be processed before the Sitecore.Mvc.config, because it processes them in alphabetical order.

If the Sitecore.Mvc.Config file patches any part of that processor, it will be listed as the patch source.

As long as the right type is in the show config, it will work as you expect. BUT it has the potential to break if another patch file is added later that overrides the attribute.

Its normally good practice to add your own config files to a sub folder under the /App_config/Include folder, prefixed with a z - this makes sure its the last set of config changes to be merged in.

Then you can be sure that your custom config will always make it.

An alternative is to use the method here: https://jammykam.wordpress.com/2016/10/20/goodbye-z-last-custom-sitecore-config-patch-folder/ - but that will only work for newer versions of Sitecore.

1
  • Im already doing that. I have a zPatches folder. Feb 15, 2017 at 20:15
0

Its a pretty old thread but I stumbled upon a similar problem where the patch source wasn't getting replaced by my custom config patch file. I ended up completely avoiding the patch:attribute approach instead used the set:value approach.

Something like below:-

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor set:type="Framework.Pipelines.Filters.InitializeGlobalFilters, DD.Framework"/>
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

One prerequisite for this set approach is to have the configuration root node set as:- xmlns:set="http://www.sitecore.net/xmlconfig/set/"

A deeper explanation has been provided on an informative blog by Mike Skutta https://mskutta.github.io/2017/08/09/sitecore-patchinstead-in-config/

Your Answer

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

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