首页 > 解决方案 > 如何通过 Web.Config 在 cookie 中添加 SameSite:none

问题描述

我正在尝试通过 web.config 在我们所有的 cookie 中添加相同的站点:无。我使用重写规则尝试了以下操作,但无济于事:

  <outboundRules>
  <rule name="Add SameSite None">
            <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="true" />
            <action type="Rewrite" value="{R:0}; SameSite=none" />
  </outboundRules>

标签: asp.netweb-configcsrf

解决方案


尝试以下操作:

<rewrite>
  <outboundRules>
    <rule name="Add SameSite" preCondition="No SameSite">
      <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
      <action type="Rewrite" value="{R:0}; SameSite=none" />
      <conditions>
      </conditions>
    </rule>
    <preConditions>
      <preCondition name="No SameSite">
        <add input="{RESPONSE_Set_Cookie}" pattern="." />
        <add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=none" negate="true" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

推荐阅读