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) {
}
}
}
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)httpRequestProcessed
will be too late for sure. Suggest you move your processor earlier in thehttpRequestPipeline
, maybe trypatch:before="*[Sitecore.Mvc.Pipelines.HttpRequest.TransferRoutedRequest, Sitecore.Mvc]"
instead.