0

If a cookie is added in any of the sitecore pipelines, it will already be in HttpContext.Current.Request.Cookies in the next pipeline. I have to check if the browser sent any cookies, but because of this I can't use HttpContext.Current.Request.Cookies as I can't be sure if a cookie in it was sent by the browser or added by code. Is there any solution to this?

When adding cookies in code:

HttpContext.Current.Response.Cookies.Add(cookie);

When reading cookies in other pipelines for the same request:

HttpContext.Current.Request.Cookies.Get(name);
1
  • Welcome to sitecore stack exchange. Could you please add more details to the question as to where you are trying to read the cookies from the browser and how you are adding them from the pipelines? – Cristi Vulturar Apr 13 at 17:11
0

If you are referring to the cookies that sitecore is using, you can take a look at the documentation to see the full list of cookies https://doc.sitecore.com/developers/93/platform-administration-and-architecture/en/cookies-used-by-sitecore.html. Then in your code you would just handle the rest.

If you need to handle the case where custom cookies might be added in other pipelines, you could implement your own pipeline and have it registered before the custom ones, for example if you take a look at the sitecore pipeline:

<httpRequestBegin>
    <processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.HttpRequest.EnsureServerUrl, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.HttpRequest.StartMeasurements, Sitecore.Kernel"/>
    <processor type="Sitecore.Analytics.Pipelines.HttpRequest.StartDiagnostics,Sitecore.Analytics" patch:source="Sitecore.Analytics.Tracking.config"/>
    ....
<httpRequestBegin>

You would register your custom processor like this:

<pipelines>
  <httpRequestBegin>
     <processor patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" type="YourNamespace.CustomProcessor, YourProject" />
    </httpRequestBegin>
</pipelines>
1
  • Yes, that's the only solution I could think of too. I wanted to see if this is a known issue or I was just missing something. – Aron Toth Apr 15 at 12:24

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.