Samesite cookie not working on DXP

As the previous post related to Samesite cookie: https://khanhpham2411.blogspot.com/2020/11/samesite-cookie-login-troubleshooting.html

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
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 contextstring keystring value,
    CookieOptions options)
    {
      CheckSameSite(contextoptions);
      _innerManager.AppendResponseCookie(contextkeyvalueoptions);
    }

    public void DeleteCookie(IOwinContext contextstring keyCookieOptions options)
    {
      CheckSameSite(contextoptions);
      _innerManager.DeleteCookie(contextkeyoptions);
    }

    public string GetRequestCookie(IOwinContext contextstring key)
    {
      return _innerManager.GetRequestCookie(contextkey);
    }

    private void CheckSameSite(IOwinContext contextCookieOptions options)
    {
      options.SameSite = SameSiteMode.None;
      options.Secure = true;
    }
  }
}

3. In your Startup.cs file, set the new Cookie Manager for your authentication
CookieManager = new SameSiteCookieManager(new SystemWebCookieManager()),

Comments

Popular posts from this blog

Optimizely Content Graph: minimal setup for testing

Episerver ServiceAPI: Example of how-to properly call the media upload

SameSite Cookie login troubleshooting