2

I'm using Sitecore 9.0.2.

I am implementing Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, that in Sitecore 9.0.2 has a constructor with the following signature:

public FilterUrlExtensions(string allowed, string blocked, string streamFiles, string doNotStreamFiles);

And my own class looks like this:

public class CustomPreprocessor : Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions
{ 
    public CustomPreprocessor(string allowed, string blocked, string streamFiles, string doNotStreamFiles) : base(allowed, blocked, streamFiles, doNotStreamFiles)
    {
    }

    public override void Process(PreprocessRequestArgs args)
    {
        base.Process(args);
    }
}

Yet I'm still getting this error: Could not create instance of type: eSundhedWeb.Foundation.Permissions.Pipelines.CustomPreprocessor. No matching constructor was found.

What can be the cause for this?

The reason why I'm trying to override the preprocessor is because I serve media files they don't seem to enter into the HttpRequest pipeline where I'm doing some authentication. I read somewhere that the preprocessor might be sending it straight to MVC because media is served as .ashx. If you've got a better idea I'm grateful for clues.

EDIT: I'm registering the processor as such in a config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="eSundhedWeb.Foundation.Permissions.Pipelines.CustomPreprocessor, eSundhedWeb.Foundation.Permissions" patch:instead="processor[@type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel']" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>
  • How did you register your preprocessor? – Marek Musielak Aug 16 '19 at 9:39
2

Try to modify your patch config the following way:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="eSundhedWeb.Foundation.Permissions.Pipelines.CustomPreprocessor, eSundhedWeb.Foundation.Permissions" patch:instead="processor[@type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel']">
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx</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)"/>
        </processor>
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

An even better solution would be to patch the configuration like this, then you don't need to copy the default values:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel" set:type="eSundhedWeb.Foundation.Permissions.Pipelines.CustomPreprocessor, eSundhedWeb.Foundation.Permissions" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>
| improve this answer | |
  • This did the trick, but now Sitecore cannot find my Process method. – Jakup Güven Aug 16 '19 at 10:43
  • But that's another question, right? I suggest you mark Tamas answer as correct and ask another question describing how you registered your preprocessor and how Sitecore cannot find your process method now. – Marek Musielak Aug 16 '19 at 10:48
  • @JakupGüven check my second option, this would be a better solution if it works for you. – Tamás Tárnok Aug 16 '19 at 11:22
0

You shall use resolve=true to initialize parametrized constructor in Sitecore

For Example here cache key is been overridden and need to use the parameterized constructor


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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