2013-05-25 25 views
8

我需要創建一個Sitecore包含修補程序文件,以將字符串添加到web.config中IgnoreUrlPrefixes設置的現有值屬性中。如何使用Sitecore包含文件修補屬性值

我試圖完全用下面覆蓋默認忽略前綴包括文件:

<?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/的是,我想添加到默認前綴的網址前綴。 ShowConfig.aspx標識修改的配置尚未應用。

理想情況下,我希望能夠簡單地將/foo/添加到作爲默認IgnoreUrlPrefixes值存在的任何值。有誰知道這是否可能以及如何在Sitecore補丁語法中指定它?

回答

12

很好的解釋所有的可能性Sitecore包括配置文件可以在這John West blog post找到。

正如你可以在鏈接後發現:

patch:attribute: Define or replace the specified attribute. 

它不允許「加/foo/到任何存在作爲默認IgnoreUrlPrefixes」屬性。

+2

感謝馬拉什確認那麼快。我原來的文件中有一個輸入錯誤,導致它無法加載。 我已經結束了使用'set:value'語法,因爲它對於閱讀文件的任何人來說都更加直觀。 –

+1

不幸的是,現在已經死了 – Liam

2

我最近遇到了同樣的問題,它似乎像馬克烏爾西諾發表了一篇博客就這一具體問題:

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); 
      } 
     } 
    } 
} 
+0

感謝您的更新和代碼片段。 我確實在過度使用流水線處理器來處理這類任務方面有所保留。在我看來,他們已經成爲我們的黃金錘子,解決了所有問題,但也許在所有情況下都不是正確的解決方案。例如配置補丁處理器正在'httpRequestBegin'管道中運行。這將會被調用很多,並且在大多數情況下,流水線處理器與請求無關。有興趣聽到你的想法。 –

+0

如果您查看現有的Ignore處理程序,您會發現它也在httpRequestBegin管道中運行,所以至少在此特定情況下它與現有體系結構保持一致。我相信配置工廠只在初始化期間加載配置時才調用「AddPaths」,所以在請求處理期間它只是檢查當前請求是否應該被忽略。如果此時不運行此檢查,則無法中止管道並執行管道,即使整個目的是停止管道。 –

+0

我的這個解決方案的實際問題是它不能更新原始列表,它只是創建它自己的「額外」列表。 Sitecore似乎還沒有公開任何公開的方式來訪問被忽略的URL列表,因此您實際上無法更改Sitecore處理器已經使用的列表。這將是最好的方式... –

相關問題