【问题标题】:IIS Samesite Cookie working for Lax and Strict but does not work for NoneIIS Samesite Cookie 适用于 Lax 和 Strict,但不适用于 None
【发布时间】:2020-08-19 16:12:09
【问题描述】:

如果我遗漏了什么,有人可以发现吗?

按照https://docs.microsoft.com/en-us/aspnet/samesite/system-web-samesite 的指示,这是我为 Strict 获得的 IIS web.config:

<system.web>
  <anonymousIdentification cookieRequireSSL="true" />
  <authentication>
   <forms cookieSameSite="Strict" requireSSL="true" />
  </authentication>
  <sessionState cookieSameSite="Strict" />
  <httpCookies sameSite="Strict" requireSSL="true" />
  <roleManager cookieRequireSSL="true" />

  <compilation targetFramework="4.7">
    ...
  </compilation>
  ...
  <httpRuntime targetFramework="4.7"/>
</system.web>

结果(抱歉,我无法直接嵌入图像。出现错误“无法到达 Imgur”):

samesite="Strict" image

对于 SameSite="None",我只是将所有“Strict”更改为“None”:

<system.web>
  <anonymousIdentification cookieRequireSSL="true" />
  <authentication>
   <forms cookieSameSite="None" requireSSL="true" />
  </authentication>
  <sessionState cookieSameSite="None" />
  <httpCookies sameSite="None" requireSSL="true" />
  <roleManager cookieRequireSSL="true" />

  <compilation targetFramework="4.7">
    ...
  </compilation>
  ...
  <httpRuntime targetFramework="4.7"/>
</system.web>

但它没有被添加到 cookie 中:

samesite="None" image

提前致谢。感谢您的帮助。

【问题讨论】:

    标签: iis configuration httpcookie samesite


    【解决方案1】:

    由于在机器上安装任何软件的麻烦,我正在考虑作为最后的手段尝试另一个线程中的评论。它与我的场景不完全匹配,因为即使他使用“Strict”也无法正常工作。但是,它确实在安装 URL Rewrite 后解决了我的问题。

    我在 .Net 4.7.2 中尝试使用 &lt;httpCookies sameSite="Strict" /&gt;,但它不适用于 Asp.Net Identity cookie。这个重写规则做到了。 – Augusto Barreto 2018 年 11 月 22 日 22:30

    @AugustoBarreto Asp.Net Identity 忽略 .config 设置。解决方案是实现自己的 Cookie 处理程序。从System.IdentityModel.Services.CookieHandler 派生并实现WriteInternal 方法。 – Saftpresse99 2019 年 3 月 18 日 12:18

    谢谢,奥古斯托!

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 1970-01-01
      • 2020-05-23
      • 2020-05-21
      • 2020-05-16
      • 2021-08-20
      • 2016-04-25
      • 2013-04-30
      • 1970-01-01
      相关资源
      最近更新 更多