iis - 如果文件不存在,则重写时 IIS 8.5 缓存问题
问题描述
我需要在 IIS 中实现以下目标:
- 使用没有缓存的 url检查更改的
.txt
文件dir
http://server/dir/test.txt
empty.txt
如果文件不存在,则重写 url
我的配置:
<rewrite>
<rules>
<rule name="test-txt" patternSyntax="Wildcard" stopProcessing="true">
<match url="*.txt" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="empty.txt" />
</rule>
</rules>
</rewrite>
<caching>
<profiles>
<add extension=".txt" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles>
</caching>
如果文件被更改,我会得到代码 200 和实际内容。按预期工作。
如果文件未更改 - 304。按预期工作。
如果文件被删除,在第一次检查后我得到错误 404.0。为什么?
在第二次请求后,我得到代码 200 和empty.txt
. 按预期工作。
如果我当时创建文件,它会按预期工作。但是,如果在很短的时间间隔内(每 3-4 秒)发出请求,则文件是否存在都无关紧要,如果我更改它test.txt
,我会得到代码 304 或内容。empty.txt
但是,如果我停止请求文件几分钟,它会再次按预期工作。
看起来 IIS 具有某种用于静态文件检查的缓存。如何仅使用静态文件使其按预期工作?(如果可能的话,不会出现错误 404)
解决方案
它不是输出缓存,它只是关于浏览器缓存。
因此,如果您想阻止特定文件夹的缓存,请将其放在您的网站/应用程序的根 web.config 中。在这种情况下,您必须禁用 example.txt 和 dir 目录的位置路径
<location path="dir">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<location path="empty.txt">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
如果要禁用所有站点的浏览器缓存,请设置
<clientCache cacheControlMode="DisableCache" />
没有位置属性。
您的规则在我这边运行良好,因此您只需为所需的文件夹/文件禁用客户端缓存。
推荐阅读
- laravel - 如何在 laravel 雄辩的关系中通过品牌获得产品类别
- google-sheets - 使用公式自定义格式
- r - 给定另一个数据集的字符串变量,如何创建新变量?
- javascript - 将模板文字与替换一起使用
- r - 转置 data.frame 并计算每列的非 NA 值
- bash - 使用 sed 从具有特殊字符的字符串中删除子字符串
- java - Java使用(管道)“... -f nut - | ffmpeg -i - ...”执行ffmpeg命令只是挂起
- php - 绕过会话验证 php
- c# - Visual Studio 2017 - 从 xaml 自动生成代码中的方法?
- python - 使用轮文件通过 pip 安装时强制执行包顺序