Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to patch an attribute value with a Sitecore Include file

I need to create a Sitecore include patch file to add a string to the existing value attribute of the IgnoreUrlPrefixes setting in the web.config.

I have tried to overwriting the default ignored prefixes entirely with the following include file:

<?xml version="1.0"?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
            <settings>
                <setting name="IgnoreUrlPrefixes">
                    <patch:attribute name="value">/foo/|/sitecore/default.aspx|/trace.axd|/webresource.axd|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.DialogHandler.aspx|/sitecore/shell/applications/content manager/telerik.web.ui.dialoghandler.aspx|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.SpellCheckHandler.axd|/Telerik.Web.UI.WebResource.axd|/sitecore/admin/upgrade/|/layouts/testing</patch:attribute>
                </setting>
            </settings>
        </sitecore>
    </configuration>
</settings>

Where /foo/ is the url prefix that I would like to add to the default prefixes. ShowConfig.aspx identifies that the modified configuration has not been applied.

Ideally I would like to be able to simply add /foo/ to whatever exists as the default IgnoreUrlPrefixes values. Does anyone know if this is possible and how to specify it in Sitecore patch syntax?

like image 310
Kevin Obee Avatar asked May 25 '13 20:05

Kevin Obee


2 Answers

Good explanation of all possibilities of Sitecore include config files can be found in this John West blog post.

As you can find in the linked post:

patch:attribute: Define or replace the specified attribute.

It does not allow to "add /foo/ to whatever exists as the default IgnoreUrlPrefixes" attribute.

like image 152
Marek Musielak Avatar answered Oct 21 '22 18:10

Marek Musielak


I recently ran into this same issue and it seems like Mark Ursino posted a blog on this particular issue:

http://firebreaksice.com/sitecore-patchable-ignore-lists/

In his example, he executes a custom pipeline after the default Sitecore one to update the value.

So instead, I’ve created a new pipeline processor that comes after the built-in one (which will support the existing native IgnoreUrlPrefixes setting) and will allow you to add each path via its own XML config node. The advantage here is you can patch and continue to patch on without needing to copy the existing values.

Sample patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor type="Sitecore.PatchableIgnoreList.ProcessPatchedIgnores, Sitecore.PatchableIgnoreList"
                   patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.IgnoreList, Sitecore.Kernel']">
          <Paths hint="list:AddPaths">
            <foo>/foo</foo>
            <bar>/bar</bar>
          </Paths>
        </processor>
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

Source code for the pipeline processor, from the blog:

using Sitecore.Collections;
using Sitecore.Pipelines.HttpRequest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Sitecore.PatchableIgnoreList
{
    public class ProcessPatchedIgnores : HttpRequestProcessor
    {
        private List<string> _paths = new List<string>();

        public override void Process(HttpRequestArgs args)
        {
            string filePath = args.Url.FilePath;

            foreach (string path in _paths)
            {
                if (filePath.StartsWith(path, StringComparison.OrdinalIgnoreCase))
                {
                    args.AbortPipeline();
                    return;
                }
            }
        }

        public void AddPaths(string path)
        {
            if (!string.IsNullOrEmpty(path) && !_paths.Contains(path))
            {
                _paths.Add(path);
            }
        }
    }
}
like image 35
Jay S Avatar answered Oct 21 '22 19:10

Jay S