Tuesday, May 10, 2016

Wrong Way to Patch Processor Params with Sitecore Patch Files

Recently, I had to look into an issue where Sitecore Rich Text Editor starts to display some buttons incorrectly on Hyperlink Manager popup window, as shown below






And when checked using Firebug, I can see that Sitecore is returning 500 error for ScriptResource.axd Urls.


http://<hostname>/ScriptResource.axd?d=5WkzNtzG0Iu_bSt84IS-lYFjFGuFXd3pdFFzPJGdqcFIuGYf2XpqGIuCBTqN9bJIQAaJ2kch7IJgHvqLtwY9fHsn0fn-cX5VNiqGRLNDhdxtCd6aGXAbZEUgdiGQtJ1ktTGlF3pRIhHkY1NQhI_YZAHBEZQLMlfWmgnlHln8D8A1&t=40eb3b32




When checked with ShowConfig.aspx, it turns out to be "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions" processor has been removed from "preprocessRequest" pipeline.

So, when checked our custom configuration files added into /App_Config/Includes/zzz folder, I can see there was a configuration file with following configurations. With this, developer has tried to patch Sitecore connfigurations, but in a wrong way.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <preprocessRequest>
        <processor patch:instead="processor[@type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel']" type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, abc</param>
          <param desc="Blocked extensions (comma separated)">*</param>
          <param desc="Blocked extensions that stream files (comma separated)">*</param>
          <param desc="Blocked extensions that do not stream files (comma separated)">
          </param>
        </processor>
      </preprocessRequest>
    </pipelines>
  </sitecore>
</configuration>


As you can see, even though above config has used "patch:instead", it uses same "type" value, which makes Sitecore to totally remove the above processor from configs.

One correct way to achieve above requirement is mention below. That configuration will replace the "param" value with new given value (i.e. "aspx, ashx, asmx, abc")


<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <preprocessRequest>
        <processor type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel'>
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, abc</param>
          </param>
        </processor>
      </preprocessRequest>
    </pipelines>
  </sitecore>
</configuration>

Happy Sitecore !!

No comments:

Post a Comment