将条目链接粘贴到浏览器中时,身份验证可以正常工作。但是,当从其他域重定向时,它会失败(调用SignInAsync后,HttpContext.User.Identity.IsAuthenticated为false)。
正在调用的应用程序具有
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Referrer-Policy", "no-referrer");
await next();
});
并且确实没有在标头中发送HTTP引用。
那是怎么回事?
这是一个.net core 2.2应用程序,我的服务配置是:
services.Configure<CookiePolicyOptions>(options =>
{
options.MinimumSameSitePolicy = SameSiteMode.Lax;
});
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());//turns off AntiForgery checking
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.SameSite = SameSiteMode.Lax;
options.AccessDeniedPath = "/AccessDenied";
});
和身份验证:
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, NameString)
};
var claimsIdentity = new ClaimsIdentity(
claims, CookieAuthenticationDefaults.AuthenticationScheme);
AuthenticationProperties properties = new AuthenticationProperties
{
IsPersistent = false
};
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
properties);
答案 0 :(得分:0)
该解决方案就像在SametimeCookiePolicyOptions和AddCookie调用上都使用SameSiteMode一样简单。