1

Is it possible to use Pipelines and call specific action method on every page?

I'm trying to build a Modal Popup based on User IP. it will redirect the user to a user specific country.

But this Action Method needs to be called from every page. I'm still wrapping my brain around how the process will invoke my action?

1
  • Can you please add some more details to your Question? Commented Jul 1, 2022 at 6:41

2 Answers 2

1

One of the most comment approaches is using httpRequestBegin pipeline. You should be aware that this pipeline is called not only for pages though.

If you use mvc, you can use mvc.requestBegin pipeline

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
     <mvc.requestBegin>
       <processor type="MyAssembly.MyNamespace.MyProcessor, MyAssembly"
                  patch:after="processor[@type='Sitecore.Mvc.Analytics.Pipelines.MvcEvents.RequestBegin.StartTracking, Sitecore.Mvc.Analytics']"
                  resolve="true">
       </processor>
     </mvc.requestBegin>
    </pipelines>
  </sitecore>
</configuration>
public class MyProcessor : RequestBeginProcessor
{
  public override void Process(RequestBeginArgs args)
  {
  }
}

EDIT

If you want to call a Controller Action on every single page, add code like below to cshtml file of your Layout:

Html.Sitecore().Controller("Controller Name", "Controller Action")
4
  • How will the process indirectly call the controller?
    – Suman Baul
    Commented Jul 4, 2022 at 17:50
  • Answer edited. Check "EDIT" section
    – Marek Musielak
    Commented Jul 5, 2022 at 8:28
  • Thanks Marek. So I don't need to invoke Pipelines for this right?
    – Suman Baul
    Commented Jul 5, 2022 at 15:08
  • 1
    Yes, no need for pipelines. Your question wasn't clear for me
    – Marek Musielak
    Commented Jul 6, 2022 at 6:08
0

A short answer is Yes.

For example, if you want to change the output of the current request dynamically you can use the getPageRendering pipeline with some additional processors. In a generic case you can always extend the HttpBeginRequest pipeline, just note that it is being executed for all Sitecore pages including the shell ones.

See all available Sitecore pipelines here.

A classic example of how to extend / create pipelines can be found here.

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.