1
votes

I´m trying to perform some actions in the pipeline "httpRequestBegin" only when necessary. My processor is executed after Sitecore resolves the user (processor type="Sitecore.Pipelines.HttpRequest.UserResolver, Sitecore.Kernel" ), as i´m resolving the user too if Sitecore is not able to resolve it first.

Later, i want to add some rendering in the pipeline "insertRenderings", only if actions in the previous pipeline were executed (If i resolved the user, show a message), so i´m trying to save some "flag" in the first step, to check in the second. My question is, where can I store that flag? I´m trying to find some kind of "per request" cache...

So far, I've tried:

  • The session: Wrong, it's too early, session doesn't exists yet.
  • Items (HttpContext.Current.Items): It doesn't work either, my item is not there on the seconds step.

So far i'm using the application cache (HttpContext.Current.Cache) with some unique key, but I don´t like this solution.

Anybody body knows a better approach to share this "flag"?

3
Could you update your question to flesh out what you're doing in httpRequestBegin? Also, where in httpRequestBegin the does your processor occur? - Martin Davies
Question updated. I´m resolving the user just after the sitecore user resolved is executed. - Vicent Galiana
Could you solve the problem by checking the active user in your insertrenderings processor (perhaps their domain or role)? - Martin Davies
There isn't anything on the user properties telling me if "I" resolved it or sitecore did. I thought about adding some property to the profile, but i don't like the idea of having to store it phisically in the core database. Do you know if it's possible to save properties in memory and reuse them later? - Vicent Galiana
Try using Sitecore.Context.Items collection. - Rosen Petrov

3 Answers

1
votes

You could add a flag to the request header and then check it's existence in the latter pipelines, e.g.

// in HttpRequest pipeline
HttpContext.Current.Request.Headers.Add("CustomUserResolve", "true");

// in InsertRenderings pipeline
var customUserResolve = HttpContext.Current.Request.Headers["CustomUserResolve"];
if (Sitecore.MainUtil.GetBool(customUserResolve, false))
{
    // custom logic goes here
}

This feels a little dirty, I think adding to Request.QueryString or Request.Params would been nicer but those are readonly. However, if you only need this for a one time deal (i.e. only the first time it is resolved) then it will work since in the next request the Headers are back to default without your custom header added.

0
votes

HttpContext.Current.Cache or HttpRuntime.Cache could be the fastest solution here. Though this approach would not preserve data when the AppPool gets recycled. If you add only a few keys to the cache and then maintain them, this solution might work for you. If each request puts an entry into the cache, it may eventually overflow the memory used by worker process in a long run.

As alternative to this you may try to use Sitecore.Context.ClientData property. It uses ClientDataStore that employs a database (look for clientDataStore section in the web.config file) to store data. These entries can survive the AppPool recycle. Though if you use them a lot, it may become a bottleneck under the load when you need to write to and/or read from the entries. If you do know that there could be a lot of entries created for sharing purposes, I'd create a scheduled task to clean up the data store from obsolete entries.

0
votes

I know this is a very old question, but I just want post solution I worked around

Below will hold data per http request basis. HttpContext.Current.Items["ModuleInfo"] = "Custom Module Info"

we can store data to httpcontext in one sitecore pipeline and retrieve in another...

https://www.codeproject.com/Articles/146455/When-Can-We-Use-HttpContext-Current-Items-to-Store