Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent IIS 7.5 from caching symlink content?

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:

  • http://forums.iis.net/t/1166077.aspx
  • http://forums.iis.net/t/1171204.aspx

Any hints how to solve this problem?

like image 570
TN. Avatar asked Jul 14 '11 18:07

TN.


3 Answers

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
like image 199
Banin Avatar answered Nov 11 '22 17:11

Banin


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

like image 39
Grimace of Despair Avatar answered Nov 11 '22 17:11

Grimace of Despair


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!!!");
    }
  }
}
like image 1
Raman Zhylich Avatar answered Nov 11 '22 18:11

Raman Zhylich