How do I prevent IIS 7.5 from caching symlink content?
Asked Answered
L

3

19

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?

Loreeloreen answered 14/7, 2011 at 18:55 Comment(2)
Recycling the app pool should update those files- not a solution per se, however.Mcneely
(Yes, recycling the app pool discards the cache.)Loreeloreen
Y
22

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
Yard answered 5/1, 2012 at 18:56 Comment(10)
Is it possible to setup it per web site?Loreeloreen
Unfortunately, no. The registry value turns off caching globally.Yard
+1 Ok, thanks for hint. But I cannot use it -- since I need it for one site only:(Loreeloreen
So happy. This was brutal to track down.Dragone
Has anyone tried this on IIS8.5? I'm having the cache issue specifically with any non-static file (web.config, .aspx, etc...) In order for the changes to appear I have to do a full app pool restart.Erudition
This solve my issues on IIS7. I've since migrated to Windows 10 with IIS 10, applied the fix, but I'm getting a stale cache on static resources again :(Bronchitis
2017, Windows 10, IIS 10, none of the proposed solutions worked for me.Duval
@SaeedNeamati Were you ever able to fix this issue?Dogy
@GrimaceofDespair Were you ever able to fix this issue?Dogy
@Erudition Were you ever able to fix this issue?Dogy
B
2

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

Bronchitis answered 24/3, 2016 at 5:56 Comment(1)
Note that OP already disabled Kernel Caching (enableKernelCache="false"). Unfortunately, this solution does not work for me on IIS 10. Same result.Dogy
S
1

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!!!");
    }
  }
}
Situs answered 3/2, 2017 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.