Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 views
in Technique[技术] by (71.8m points)

xml - How do I disable caching of an individual file in IIS 7 using weserver config settings

Is there any way to diable the caching of a single javascript file in my ASP.NET applicaiton without disabling the caching of any other files in the application?

It is running on IIS 7 in Azure, so to me it seems that my only options of controlling this are within the webserver tags.

I currently use the folowwing config, but this is disabling cache on all files.

     <modules runAllManagedModulesForAllRequests="true"/>

    <staticContent>
      <clientCache cacheControlMode="DisableCache"/>
    </staticContent>

  </system.webServer>

I just want to disable cache of a single javascript file that changes quite often.

Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just stumbled across this question; you can use the following to disable the cache on a specific file:

<configuration>
  <location path="path/to/the/file">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

(Note that the path is relative to the web.config file)

Alternatively, place the single file in a directory on it's own, and give that directory it's own web.config that disables caching for everything in it;

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

[Both tested on IIS7.5 on Windows 7, but you'll have to confirm that it works OK on Azure]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...