【发布时间】:2020-08-11 06:52:45
【问题描述】:
我有一个 .net MVC 5 应用程序。 AuthCookie 在没有 iframe 的情况下工作正常,我可以看到 SameSite 策略设置为无。但是,在 iframe 中,[Authorize] 属性方法卡在永久重定向上。在 iframe 中,请求似乎无法读取下面代码创建的 cookie。
我followed the documentation并实现SameSiteCookieManager.cs
网络配置
<httpCookies sameSite="None" requireSSL="true" />
<sessionState cookieSameSite="None">
</sessionState>
<authentication mode="None" />
<compilation targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
启动
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
CookieManager = new SameSiteCookieManager(new SystemWebCookieManager()),
CookieSameSite = SameSiteMode.None,
CookieHttpOnly = true,
CookieSecure = CookieSecureOption.Always,
ExpireTimeSpan = new TimeSpan(0, 10, 0)
});
帐户/登录
var user = UserManager.Find(userName,"*****");
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
var identity = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
return RedirectToAction("Index", "Home");
【问题讨论】:
标签: asp.net-mvc iframe samesite