3

We have a multisite instance, and for a particular site ("mysite"), the requirement is as follows:

When visitor logs in using the Social connector, prevent the user record being saved in Sitecore User Manager.

To achieve this, I replaced the existing attribute in the config with a custom one.

Sitecore.Social.config

<social.matchUser>
 .....
 .....
 <!--<processor type="Sitecore.Social.Connector.Pipelines.MatchUser.CreateUser, Sitecore.Social" />-->
 <processor type="MySite.Foundation.Common.SitecoreExtensions+MySiteSocial, MySite.Foundation.Common" />        
</social.matchUser>

SitecoreExtensions.cs

public class SitecoreExtensions
{
  public class MySiteSocial
  {
     public void Process(SelectUserPipelineArgs args)
     {
       //code as it is in the Sitecore.Social dll
       .....
       //condition to not save user for certain site
       if(Sitecore.Context.GetSiteName() != "MySite")
       {
         args.Result = this.CreateSitecoreUser(fullName, args.Email, args.AccountBasicData.FullName);
       }    
     }
   }
 }

Though this might work, I know this is not the right way to patch a custom process. How should I patch the processor the right way and also ensure that this in only for a certain site.

2

Could you please try this. I have tried the same for httprequestbegin pipeline, it’s working fine :)

Configuration as follows:

<social.matchUser>
 .....
 .....
 <!--<processor type="Sitecore.Social.Connector.Pipelines.MatchUser.CreateUser, Sitecore.Social" />-->
 <processor type="MySite.Foundation.Common.FilteredPipeline, MySite.Foundation.Common" >
<sites hint="list">
        <site>site1</site>
        <site>site2</site>
      </sites>        
</social.matchUser>

Codebehind as follows:

public class FilteredPipeline
{
    public List<string> Sites { get; set; }

    public FilteredPipeline()
    {
        Sites = new List<string>();
    }

    public override void Process(SelectUserPipelineArgs args)
    {
        if (!Sites.Contains(Sitecore.Context.Site.Name))
            return;

        // run your site specific code
    }
}

For more : https://jammykam.wordpress.com/2014/08/26/creating-site-specific-pipelines-for-multi-site-implementation-in-sitecore-cms/

2
  • When overriding a process should all the code in the original method be also included or not necessary?
    – Qwerty
    Mar 17 '17 at 10:01
  • Depends on your objective.. Most of the time, you probably want the code that Sitecore is trying to do, plus whatever changes.. But, it ultimately boils down to what you are trying to achieve. Each processor and their function are completely unique. Mar 18 '17 at 4:18
1

You should follow next solution. Please look also on the link that I provided you.

The configuration for this processor looks like this:

<httpRequestBegin>
  <processor type="ParTech.Pipelines.HttpRequestBegin.ItemVersionValidator, ParTech"
         patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel']">
  <param desc="Allowed sites">my-sitename-a, my-sitename-b, my-sitename-c</param>
 </processor>
</httpRequestBegin>

The class will look like:

  using System;
  using System.Linq;
  using Sitecore;

  /// <summary>
  /// Sitecore pipeline processor which can be configured to run only for    specific sites.
 /// </summary>
 public abstract class IsolatedProcessor
 {
    private readonly string[] allowedSites;

    /// <summary>
   /// Initializes a new instance of the <see cref="IsolatedProcessor" /> class.
  /// </summary>
  /// <param name="allowedSites">
   /// Comma-separated string with names of the sites for which this processor must run.
   /// </param>
protected IsolatedProcessor(string allowedSites)
{
    this.allowedSites = (allowedSites ?? string.Empty)
        .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
        .Select(x => x.ToLower().Trim())
        .ToArray();
}

/// <summary>
/// Gets a value indicating whether this instance is allowed to run in the current context.
/// </summary>
protected bool IsAllowedRequest
{
    get 
    {
        return this.allowedSites.Length == 0 
            || this.allowedSites.Contains(Context.GetSiteName().ToLower());
    }
 }
}

Here is an example of how is implemented the IsolatedProcessor for the ItemVersionValidator processor.

public class ItemVersionValidator : IsolatedProcessor
{
public ItemVersionValidator(string allowedSites = null)
    : base(allowedSites)
{
}

public void Process(HttpRequestArgs args)
{
    // Only process allowed requests.
    if (!this.IsAllowedRequest)
    {
        return;
    }

    // Execute processor logic.
    if (Context.Item != null && Context.Item.Versions.Count == 0)
    {
        Context.Item = null;
    }
  }
}

More information you can find here: http://www.partech.nl/nl/blog/2014/09/isolating-pipeline-processors-and-event-handlers

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.