【问题标题】:IIS Internet Information Server no-cache setting in web.configweb.config 中的 IIS Internet Information Server 无缓存设置
【发布时间】:2021-01-05 18:42:53
【问题描述】:
我正在使用 IIS 开发 Azure 服务;但是,我无法使 web.config 与无缓存一起使用。
如何将其更改为无缓存并覆盖所有 js 脚本?
【问题讨论】:
标签:
web
iis
web-config
no-cache
【解决方案1】:
如果我理解正确,你问的是如何在 JS 中禁用缓存 IIS 缓存
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var clientCacheElement = staticContentSection.ChildElements.Item("clientCache");
clientCacheElement.Properties.Item("cacheControlMode").Value = "DisableCache";
adminManager.CommitChanges();
或通过 web.config 禁用请求缓存:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</configuration>
参考:https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache