4

I have written a custom processor in Sitecore to set the context language and country code. I am calling this processor on httpRequestBegin pipeline. The problem I am facing is that the processor is executing multiple times on page load for each component load. Below is my patch config file:

<httpRequestBegin>
  <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.FileResolver, Sitecore.Kernel']" type="custom-processor class, custom-processor" />   
</httpRequestBegin>

Now I want to restrict my processor to execute only one time on page load and not on each component laod.

Please let me know how can I do this.

2 Answers 2

3

It's probably executing several times because your page may also have other Sitecore assets like images that it's downloading. This means that the httpBeginRequest will be called since it gets triggered all the time through the HttpApplication.BeginRequest. So, it's OK that it gets called all the time but you may want to do some checks first to make sure that the core of your processor only gets executed once or even for specific types of requests only.

5
  • What is way to check in Pipeline that will execute the processor for only specfic type of requests Commented Feb 1, 2018 at 17:02
  • Can i add the custom header to response and then check it next time if the value is present then do not execute some kind of that Commented Feb 1, 2018 at 17:34
  • You can use the template ID (name) so it only execute for those types of pages. You don't really want the header since the system doesn't really know that a particular request is triggered by another request (page). Plus, that header may not be there for the other requests (images, etc.). If you probably post another question with details on what your criteria is for executing it only once, that might help.
    – Marco
    Commented Feb 1, 2018 at 17:41
  • We need to have pipeline which hits first time when user access the URL of site . Pipeline will get the User location from GeoIP Module and set the language code for that country and this has to be done only once in beginning while searching we do not want pipeline to be executed and search is just a text box no template Commented Feb 1, 2018 at 19:59
  • Sounds like you can just populate a session variable and check it if it's set.
    – Marco
    Commented Feb 1, 2018 at 20:13
0

Try the initialize pipeline instead.

<pipelines> <initialize> <processor type="xxx" patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']" /> </initialize> </pipelines>

2
  • 3
    This only runs once ever at application startup, not per user request.
    – jammykam
    Commented Jan 31, 2018 at 15:50
  • This is not working for us we need to have pipeline which hits first time when user access the URL of site . Pipeline will get the User location from GeoIP Module and set the language code for that country and this has to be done only once in beginning. Commented Feb 1, 2018 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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