Suppose i have 5 processor in a custom pipeline. I want to abort the execution of remaining processor if certain condition is satisfied in one of the processor.

  • 1
    You can try args.AbortPipeline(); when your condition is satisfied. args is the argument parameters you are passing to the pipeline. – adarsh Nov 22 at 6:36
up vote 9 down vote accepted

Siva Kumar answer is correct in the most simple scenario. You must know that

args.AbortPipeline()

doesn't really abort the pipeline. It only sets a flag and all the remaining processors will be still checked and there is a chance some of them WILL be executed. Why?

Sitecore allows setting one extra flag on every processor which is called RunIfAborted. If you open /sitecore/admin/showconfig.aspx, you will see this flag set e.g. for 2 processors in publishItem pipeline:

<publishItem help="Processors should derive from Sitecore.Publishing.Pipelines.PublishItem.PublishItemProcessor">
    <!-- ... -->
    <processor
      type="Sitecore.Publishing.Pipelines.PublishItem.RaiseProcessedEvent, Sitecore.Kernel" 
      runIfAborted="true"/>
    <processor
      type="Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics, Sitecore.Kernel"
      runIfAborted="true">
    <!-- ... -->
</publishItem>

This flag makes sure that the processors will be executed even if the Aborted flag is set on the args of the pipeline.

In summary, using args.AbortPipeline(); is the correct way of aborting the execution of pipeline processors, but you must remember that Sitecore may still execute some of the processors.

Pseudo code of how Sitecore pipeline works (this is not the exact code - it's just to show the basic logic part):

foreach (var processor in processors)
{
    if (!args.Aborted || processor.RunIfAborted)
        Execute(processor);
}

args.AbortPipeline() method is used to Abort the Pipeline. This method sets _aborted flag as true and ignores the successor processors from execution.

public override void Process(HttpRequestArgs args)
{
            Assert.ArgumentNotNull(args, "args");
              if (condition is true)
                {
                    args.AbortPipeline();
                    return;
                }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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