8

我需要创建一个 Sitecore 包含补丁文件,以将字符串添加到IgnoreUrlPrefixesweb.config 中设置的现有值属性。

我尝试使用以下包含文件完全覆盖默认忽略的前缀:

<?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>

/foo/我想添加到默认前缀的 url 前缀在哪里。ShowConfig.aspx标识未应用修改的配置。

理想情况下,我希望能够简单地添加/foo/作为默认IgnoreUrlPrefixes值存在的任何内容。有谁知道这是否可行以及如何在 Sitecore 补丁语法中指定它?

4

2 回答 2

12

可以在这篇John West 博客文章中找到对Sitecore包含配置文件的所有可能性的很好解释。

您可以在链接的帖子中找到:

patch:attribute: Define or replace the specified attribute.

它不允许“添加/foo/到作为默认存在的任何内容IgnoreUrlPrefixes”属性。

于 2013-05-25T20:37:18.567 回答
3

我最近遇到了同样的问题,似乎 Mark Ursino 就这个特定问题发表了一篇博客:

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

在他的示例中,他在默认 Sitecore 之后执行自定义管道以更新值。

因此,我创建了一个新的管道处理器,它位于内置处理器之后(它将支持现有的本机 IgnoreUrlPrefixes 设置),并允许您通过其自己的 XML 配置节点添加每个路径。这里的优点是您可以修补并继续修补,而无需复制现有值。

示例补丁文件:

<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>

流水线处理器的源代码,来自博客:

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);
            }
        }
    }
}
于 2017-03-06T21:02:19.370 回答