1

In my content delivery instance I have user information that is used in multiple componentized view renderings, which is sourced from REST services (some of this I want to pre-fill, some will be done via AJAX calls).

I was attempting to write a Sitecore pipeline processor which validates that the user is authenticated - then uses their authentication token to pre-load some of that information so it's available in the User Profile (or in Session). My idea was eventually to make some of this basic information available for the content editors to add via personalization rules and tokens.

I tried patching it at the end of httpBeginRequest - but this appears to only fire for the initial request (the processor does not fire hitting refresh on the page). Is this a caching issue or because it's a singleton. I did add reusable="false" to my patching config but this does not appear to make a difference.

Note - I also looked at httpRequestProcessed - but this appears to fire AFTER the page has already rendered - which I think would make it useless for what I'm trying to do.

Also - feel free to suggest I'm just not using the pipeline appropriately :)

Processor skeleton...

  public class ServiceCachingProcessor : HttpRequestProcessor
{

    public override void Process(HttpRequestArgs args)
    {


        try
        {
            if (!Sitecore.Context.User.IsAuthenticated || Sitecore.Context.User.Identity == null)
            {
                Log.Warn("User not authenticated / Identity unavailable", this);
                return;
            }

            var identity = Sitecore.Context.User.Identity as ClaimsIdentity;
            var tokenClaim = identity.Claims.First(x => x.Type.Contains("OAuthToken"));

            /// use token to pull service information if session empty
            if(Session[cachedInfo] == null) {
            ...
            }


        } catch (Exception ex) {

        }
    }
}
  • Post up the (skeleton) code of your processor, the httpBeginRequest pipeline is called once for every request. Are you using MVC, cos you may need to patch before MVC Transfer processors. If you are storing the user info in session, I would question putting this logic in a httpRequestBegin processor though, unless you really want to be checking the data against the external service every request (which seems a little crazy) – jammykam Mar 24 '18 at 17:13
  • Thanks - I will. i was planning on just checking to see if the cached data existed first - so going to the service only if it had expired or empty. – Watson Mar 24 '18 at 19:56
  • @jammykam - I agree with your questioning putting this in httpRequestBegin but is httpRequestProcessed too late? I am utilizing MVC (mostly view renderings). – Watson Mar 25 '18 at 11:44
  • 1
    httpRequestProcessed will be too late for sure. Suggest you move your processor earlier in the httpRequestPipeline, maybe try patch:before="*[Sitecore.Mvc.Pipelines.HttpRequest.TransferRoutedRequest, Sitecore.Mvc]" instead. – jammykam Mar 25 '18 at 20:02

Your Answer

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

Browse other questions tagged or ask your own question.