如何防止 IIS 7.5 缓存符号链接内容?

发布于 2024-11-20 00:12:00 字数 1082 浏览 5 评论 0原文

我已经设置 IIS 7.5 来静态提供一些文件,其中一些文件实际上是符号链接(由 mklink 创建)。

即使我禁用了内核和用户缓存,这些文件似乎仍被 IIS 以某种方式缓存。文件修改后,IIS 仍然提供旧版本服务。

为了确保它不是由 ASP.NET 引起的,我创建了一个专用的非托管 AppPool。我还检查过这些文件没有被浏览器缓存。

我的 web.config 如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
        <caching enabled="false" enableKernelCache="false" />
        <urlCompression doStaticCompression="false" doDynamicCompression="false" />
        <staticContent>
            <clientCache cacheControlMode="DisableCache" />
        </staticContent>
    </system.webServer>
</configuration>

有几个人提到这个问题:

有任何提示如何解决此问题吗?

I have set up IIS 7.5 to statically serve some files, and some of these files are actually symbolic links (created by mklink).

Even if I disabled both kernel and user caching, these files seems to be cached somehow by IIS. And IIS is still serving old versions after the files are modified.

To be sure that it is not caused by ASP.NET, I've created a dedicated unmanaged AppPool. I have also checked that these file are not cached by browsers.

My web.config is following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
        <caching enabled="false" enableKernelCache="false" />
        <urlCompression doStaticCompression="false" doDynamicCompression="false" />
        <staticContent>
            <clientCache cacheControlMode="DisableCache" />
        </staticContent>
    </system.webServer>
</configuration>

There are several people mentioning this problem:

Any hints how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兮颜 2024-11-27 00:12:00

这个问题让我发疯了大约一个月。您必须在注册表中禁用 IIS 缓存,据我所知,这在 IIS 7 的任何地方都没有记录,而是一个仍然有效的旧 IIS 5 技巧。您可以将以下内容转换为 .reg 文件并导入,也可以导航到该部分并手动添加。我建议更改此参数后重新启动,我不确定 IIS 是否会在 iisreset 后重新启动它。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters]
"DisableMemoryCache"=dword:1

This problem drove me nuts for like a month a while back. You have to disable IIS caching in the registry, as far as I know this isn't documented anywhere for IIS 7 but instead is an old IIS 5 trick that still works. You can either turn the below into a .reg file and import it or you can just navigate to the section and add it manually. I recommend rebooting after changing this parameter, I'm not sure if IIS picks it up after just an iisreset.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters]
"DisableMemoryCache"=dword:1
坏尐絯℡ 2024-11-27 00:12:00

我之前能够通过 Banin 的修复在 IIS7 上修复此问题。从那时起,我已经迁移到带有 IIS 10 的 Windows 10,并再次遇到了同样的问题。 DisableMemoryCache 没有帮助。

然后我禁用了内核缓存,目前看来,这似乎解决了问题(我对屏幕截图中的荷兰语感到抱歉):

IIS 对话框截图

I was previously able to fix this issue on IIS7 with Banin's fix. Since then, I have moved to Windows 10 with IIS 10, and suffered the same problem again. DisableMemoryCache did not help.

I then disabled kernel caching, and for now, that seems to fix the issue (I'm sorry for the Dutch in the screenshot):

IIS dialog box screenshot

芸娘子的小脾气 2024-11-27 00:12:00

巴宁的解决方案对我有用。更改注册表参数并重置 IIS 后问题得到解决。下面的 C# 程序(您可以使用 LINQPad 来运行它)将帮助您重现该问题:

using System.IO;
using System.Net;

void Main()
 {
  var virtualPath = "JunctionPoint/sample.js";
  var physicalPath = $@"C:\IISROOT\JunctionPoint\{virtualPath}";

  for (int i = 0; i < 100; i++) {   
    File.WriteAllText(physicalPath, i.ToString());

    Console.Write(i + "=");

    var client = new WebClient();
    string html = client.DownloadString($"http://localhost/{virtualPath}");
    Console.WriteLine(html);

    if (i.ToString() != html) {
      Console.WriteLine("Issue reproduced!!!");
    }
  }
}

Banin's solution worked for me. The issue was resolved after changing registry parameter and resetting IIS. The C# program below (you can use LINQPad to run it) will help you reproduce the issue:

using System.IO;
using System.Net;

void Main()
 {
  var virtualPath = "JunctionPoint/sample.js";
  var physicalPath = $@"C:\IISROOT\JunctionPoint\{virtualPath}";

  for (int i = 0; i < 100; i++) {   
    File.WriteAllText(physicalPath, i.ToString());

    Console.Write(i + "=");

    var client = new WebClient();
    string html = client.DownloadString($"http://localhost/{virtualPath}");
    Console.WriteLine(html);

    if (i.ToString() != html) {
      Console.WriteLine("Issue reproduced!!!");
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文