0

I'm new to Sitecore, for my new Project, I need to make a few customizations in cookie creation. Is there any way to force the Sitecore to create cookies with HttpOnly as 'true'? I'm using Sitecore 10 version.

enter image description here

0

1 Answer 1

1

I agree with Raman's comment, here is an addition to this, if you want to set cookie HttpOnly using code, you can do as follow

private const string helloCookieName = "HELLO_COOKIE";
var httpResponse = HttpContext.Current?.Response;
if (httpResponse != null && httpResponse.Cookies.AllKeys.Contains(helloCookieName))
{
var helloCookie = httpResponse.Cookies.Get(helloCookieName);
helloCookie.SameSite = SameSiteMode.None;
helloCookie.Secure = true;
}    

for global-level change, you can do as Raman suggests. Configure the default values of cookies in the <system.web> section of the web.config file as follows:

<httpCookies sameSite="None" requireSSL="true" />
2
  • Thanks Praveen , is there way to create a Sitecore Pipeline processor that can run after cookie creation ? <processor patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel']" type="MySite.Foundation.SitecoreExtensions.Pipelines.HttpRequestBegin.CookieProcessor, MySite.Foundation.SitecoreExtensions" /> this is working for #lang. But I need to target few more cookie types.
    – Libin
    Commented Mar 9, 2023 at 14:32
  • stackoverflow.com/questions/75674628/… - @Labit - check this, I think this question is your answer to updating existing cookie, I did not try it, but you should. Commented Mar 9, 2023 at 16:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.