asp.net - pattern="." 是什么意思 在 IIS Url Rewrite 的 preCondition 属性上?
问题描述
我见过很多 IIS URL Rewrite 的例子:
<!-- reference: https://im5tu.io/article/2017/06/ensuring-samesite-cookies-with-url-rewrite/ -->
<rewrite>
<outboundRules>
<rule name="Ensure samesite Cookies" preCondition="Missing samesite cookie">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; SameSite=strict" />
</rule>
<preConditions>
<preCondition name="Missing samesite cookie">
<!-- Dont remove the first line here, it does do stuff! -->
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=strict" negate="true" />
</preCondition>
</preconditions>
</outboundRules>
</rewrite>
有谁知道为什么<add input="{RESPONSE_Set_Cookie}" pattern="." />
需要这条线?
我尝试在 Google 上搜索,但没有找到答案。
解决方案
该规则仅在与前置条件匹配时才执行。
“模式”是一个正则表达式,可以.
匹配任何字符。
在这种情况下,基本上是说“如果 cookie 有值则匹配”。
如果 cookie 已经具有要添加的值,则它下面的行否定执行规则。
否则,每次运行规则时,您都会再次添加文本。
至于为什么需要,发送一个空的cookie应该删除它。
在这种情况下,它会在尝试使用规则更改它之前确保 cookie 中确实存在一个值。
推荐阅读
- reactjs - 使用库时,类型“元素”不可分配给类型 ReactChild[]
- amazon-cloudfront - Cloudfront 缓存行为应用不正确
- html - 如何很好地设置 html 样式?
- javascript - 事件循环是否与 JS 主线程在同一线程上运行?
- javascript - Modal通过点击调用,但立即消失(Next.js)
- swift - 快速替换 PDF 中的图像。如何获取页面中的图像位置?
- laravel - 仅当用户是管理员时 Laravel Fortify 登录
- python - 创建表并从 CSV 文件复制数据
- windows - 使用 winautomation 进程本身在 winautomation 中暂停/播放进程
- laravel - 如何对忽略数组中的当前 id 的数组应用 laravel 唯一验证?