出现这个问题的原因是Chrome浏览器不支持第三方cookie,因此我们需要对应用程序的cookie策略进行更改。
在Startup.cs文件中的ConfigureServices方法中添加以下代码:
services.Configure
然后在Login方法中添加以下代码:
var props = new AuthenticationProperties { // 设置IsPersistent为true,表示“记住我”功能可用 IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(30) };
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, props);
现在,当用户选中“记住我”复选框时,cookie会在Chrome浏览器中保存,并在以后的会话中保持已验证状态。