0

I am using Sitecore 10 with JSS Angular app, I need to set site language cookie {{mysite}}#lang to be HttpOnly so I have created the HttpRequest pipeline processor.

public class CookieProcessor : HttpRequestProcessor
{
    public List<string> Sites { get; set; }
    public CookieProcessor()
    {
        Sites = new List<string>();
    }
    public override void Process(HttpRequestArgs args)
    {
        if (!Sites.Contains(Sitecore.Context.Site.Name))
            return;
        
        var cookie = HttpContext.Current.Request.Cookies[Sitecore.Context.Site.Name+"#lang"];
        if (cookie != null)
        {
            cookie.HttpOnly = true;
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

    }
}

and this the patch config file.

<sitecore>
    <pipelines>
        <httpRequestBegin>
            <processor type="Maqta.Project.Website.CookieProcessor,Maqta.Project.Website"
                       patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" resolve="true">
                
            </processor>
        </httpRequestBegin>
    </pipelines>
</sitecore>

This change works fine for the English version but when I navigate to the Arabic version, it is set correctly first but gets overwritten after the page is fully loaded.

Maybe this happens when the cookie value is set to be "ar" instead of "en"

so any idea when cookie value set to be "ar" and if there are pipelines run after this??

Note: also I have tried to use this processor

processor[@type='Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel']

instead of ItemResolver but still the same issue

3
  • Not sure if there is enough information to answer your question I think it would need a network trace and some info on how the language gets resolved in requests from your Angular app. Did you consider setting the HttpOnly attribute through an outbound rewrite rule? This could be simpler, doing these things through pipelines always have many scenarios which can cause issues.
    – Jeroen
    Jun 2, 2022 at 14:10
  • Are you saying that the Arabic language cookie is overwritten by the English language cookie once the page loads? Jun 3, 2022 at 23:05
  • This question looks like a duplicate: stackoverflow.com/questions/65946560/… Jun 4, 2022 at 0:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.