How do I stop IIS from caching any files, ever, un

2019-04-04 14:45发布

I do some web development for work and the biggest hit to my productivity comes from IIS. It caches files that will not update even when they are changed, unless I restart IIS. Specifically, I am referring to html, js, and css files. This problem forces me to stop and start my web application constantly. Since I have Windows 7 I believe I have ISS 7.5. I am using IIS Express. This is so frustrating that I'd prefer IIS to never cache anything, ever. I am fine with a solution that stops all forms of caching or just for the project I am working on.

IIS Manager is not available to me. It is not located in System and Security -> Administrative Tools -> IIS Manager like is suggested by https://technet.microsoft.com/en-us/library/cc770472%28v=ws.10%29.aspx. Also, searching for inetmgr in the Start Search box gets me no results. Because of this, I am looking for a fix to the IIS applicationhost.config file.

I have tried putting the following in my applicationhost.config which doesn't work:

<location path="ProjectName">
    <system.webServer>
        <staticContent>
           <clientCache cacheControlCustom="public" cacheControlMode="DisableCache" />
        </staticContent>
       <caching enabled="false" enableKernelCache="false"></caching>
    </system.webServer>
</location>

The closest question on StackOverflow to my problem was IIS cached files never replaced. However, Fiddler shows me that the old files are being sent to the browser even after they have been changed.

How can IIS to send my browser the updated files without having to restart it?

3条回答
Evening l夕情丶
2楼-- · 2019-04-04 15:14

I suspect that you have enabled output caching, this would exhibit the behaviour that you are describing where recycling the app pool or restarting IIS clears them and allows you to see the new content.

This page gives more information, http://www.iis.net/learn/manage/managing-performance-settings/walkthrough-iis-output-caching

If you are using IIS Express then it is likely that the caching is set at the application level in your web.config, or on individual pages.

You need to set

<caching>
   <outputCache enableOutputCache="false" />
</caching>

or if its IIS 7+ (Which IIS Express will be)

<system.webServer>
    <caching enabled="false" />
</system.webServer>
查看更多
叛逆
3楼-- · 2019-04-04 15:15

Quite possible it's the browser which is the culprit. Have you tried ctrl+ F5 ?

查看更多
The star\"
4楼-- · 2019-04-04 15:33

If anyone stumbles upon this and wants a "mouse click" way of disabling cache in IIS 7 or so... here's an answer from IIS forums on https://forums.iis.net/t/959070.aspx :

Here's an update for IIS 7.5 (in Windows 7). Disabling the cache is a good thing to do during development when you're not concerned with performance and want to see changes take place immediately. It speeds up the development process. - Start IIS Manager (type IIS into search programs and files in start menu) - Navigate to desired site in the Connections tree (Default Web Site) - Open Output Caching - Edit Feature Settings - Uncheck Enable cache and Enable kernel cache

You get a setting in web.config file something like this:

<caching enabled="false" enableKernelCache="false">
            <profiles>
                <add extension=".css" policy="DontCache" kernelCachePolicy="DontCache" />
                <add extension=".script" policy="DontCache" kernelCachePolicy="DontCache" />
            </profiles>
        </caching>

So, no tag here..

查看更多
登录 后发表回答