IdentityServer4登录后无法跳转设置策略

在中间件中手动改变samesite属性为lax就可以解决问题;

services.Configure<CookiePolicyOptions>(options =>

{

   options.MinimumSameSitePolicy = SameSiteMode.Lax;

   options.OnAppendCookie = cookieContext =>

      CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);

   options.OnDeleteCookie = cookieContext =>

      CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);

});

private static void CheckSameSite(HttpContext httpContext, CookieOptions options)

{

   if (options.SameSite == SameSiteMode.None)

   {

      var userAgent = httpContext.Request.Headers["User-Agent"].ToString();

      if (DisallowsSameSiteNone(userAgent))

      {

         options.SameSite = SameSiteMode.Lax;

      }

   }

}

 

posted @ 2021-12-28 20:17  旅途。  阅读(214)  评论(0编辑  收藏  举报