Samesite cookie not working on DXP
As the previous post related to Samesite cookie:
It could work just fine in your local environment but when deployed to DXP the workaround using rewrite rule seem not working anymore. It might be the different .net version installed between DXP and local.Time to try some coding 🙂 Fortunately, I found a post really helpful:
Then implement it with Episerver style:
1. Make sure you are targeting project with .NET 4.7.2 and upgraded Microsoft.Owin 4.1.0
2. Add this class to the Commerce Manager site
2. Add this class to the Commerce Manager site
using Microsoft.Owin;
using Microsoft.Owin.Infrastructure;
namespace EPiServer.Reference.Commerce.Manager
{
public class SameSiteCookieManager : ICookieManager
{
private readonly ICookieManager _innerManager;
public SameSiteCookieManager() : this(new CookieManager())
{
}
public SameSiteCookieManager(ICookieManager innerManager)
{
_innerManager = innerManager;
}
public void AppendResponseCookie(IOwinContext context, string key, string value,
CookieOptions options)
{
CheckSameSite(context, options);
_innerManager.AppendResponseCookie(context, key, value, options);
}
public void DeleteCookie(IOwinContext context, string key, CookieOptions options)
{
CheckSameSite(context, options);
_innerManager.DeleteCookie(context, key, options);
}
public string GetRequestCookie(IOwinContext context, string key)
{
return _innerManager.GetRequestCookie(context, key);
}
private void CheckSameSite(IOwinContext context, CookieOptions options)
{
options.SameSite = SameSiteMode.None;
options.Secure = true;
}
}
}
CookieManager = new SameSiteCookieManager(new SystemWebCookieManager()),

Comments
Post a Comment