asp.net-mvc - 更改 FedAuth cookie 的 SameSite 属性?

标签 asp.net-mvc google-chrome cookies iframe samesite

我很难更改 ASP.NET MVC 应用程序上的 SameSite 属性。这是场景:
我正在尝试将我的 ASP.NET 应用程序加载到 iframe 中,并且由于 Google Chrome 80+ 中的更改,我需要为 cookie 设置 SameSite 属性,以便能够在 iframe 中使用身份验证 cookie。我点击了这个链接 SameSite Cookie
并应用了更改,但由于某种原因,这不会更改 FedAuth 和 FedAuth cookie 的 SameSite 属性。
下面是创建 session cookie 的代码:

SessionAuthenticationModule session = FederatedAuthentication.SessionAuthenticationModule;
SessionSecurityToken sToken = session.CreateSessionSecurityToken(principal, null, DateTime.UtcNow, DateTime.UtcNow.AddHours(24), isPersistant);
            session.AuthenticateSessionSecurityToken(sToken, true);
session.WriteSessionTokenToCookie(sToken);
web.config
<httpRuntime requestValidationMode="2.0" maxRequestLength="28672" targetFramework="4.7.2" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

<compilation debug="true" targetFramework="4.7.2">
<httpCookies httpOnlyCookies="true" sameSite="None" requireSSL="true"/>
<authentication mode="Forms">
   <forms  requireSSL="true" cookieSameSite="None"/>
</authentication>
<sessionState cookieSameSite="None" /> 

<system.identityModel.services>
    <federationConfiguration>
      <cookieHandler mode="Default" requireSsl="true" persistentSessionLifetime="0.06:00:00" path="/"/>
</federationConfiguration>
你有什么建议吗?

最佳答案

我对使用 wsfed 还是个新手,但将此添加到我的 Global.asax.cs似乎对我有用:

void WSFederationAuthenticationModule_SignedIn(object sender, EventArgs e)
{
  foreach (string key in Response.Cookies.AllKeys)
  {
    if (key.StartsWith("FedAuth"))
    {
      var cookie = Response.Cookies[key];

      cookie.SameSite = SameSiteMode.None;
      cookie.Secure = true;
    }
  }
}

关于asp.net-mvc - 更改 FedAuth cookie 的 SameSite 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64066385/

相关文章:

javascript - 选择更改时设置 Chrome 存储空间

javascript - Angular2 cookie 而不是本地存储

asp.net-mvc - 在 View 中格式化小数

asp.net-mvc - 在特定列而不是整个网格上使用 settings.CellEditorInitialize

google-chrome - 无法使用 chrome_settings_overrides 覆盖搜索提供程序

java - 用于多线程的 CookieManager

java - 添加和读取cookie

c# - 在 ASP.NET MVC 中获取负载

jquery - jquery #find 关于部分回发的问题

css - Chrome 的站点可视化问题