xml 如何使用 weserver 配置设置禁用 IIS 7 中单个文件的缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3929284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I disable caching of an individual file in IIS 7 using weserver config settings
提问by Dean
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?
有什么方法可以在我的 ASP.NET 应用程序中禁用单个 javascript 文件的缓存而不禁用应用程序中任何其他文件的缓存?
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.
它在 Azure 中的 IIS 7 上运行,所以对我来说,控制它的唯一选项似乎是在网络服务器标签内。
I currently use the folowwing config, but this is disabling cache on all files.
我目前使用 flowwing 配置,但这会禁用所有文件的缓存。
<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.
我只想禁用经常更改的单个 javascript 文件的缓存。
Is it possible?
是否可以?
回答by gdt
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)
(注意路径是相对于web.config文件的)
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;
或者,将单个文件放在它自己的目录中,并为该目录提供自己的 web.config 以禁用其中所有内容的缓存;
<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]
[均在 Windows 7 上的 IIS7.5 上进行了测试,但您必须确认它在 Azure 上运行正常]
回答by What Would Be Cool
Looks like the above answer is missing a "profiles" tag
看起来上面的答案缺少“配置文件”标签
<caching>
<profiles>
<add extension=".js" kernelCachePolicy="DontCache" policy="DontCache"/>
</profiles>
</caching>
回答by Taylor Bird
You're going to want to look at the System.WebServer/Caching class, where you can apply a caching profile to particular extensions. This will at least enable you to control it for all Javascript files ending with the .js.
您将要查看 System.WebServer/Caching 类,您可以在其中将缓存配置文件应用于特定扩展。这至少将使您能够控制所有以 .js 结尾的 Javascript 文件。
<system.webServer>
...
<caching>
<add extension=".js" policy="DontCache" kernelCachePolicy="DontCache" />
</caching>
</system.webServer>
That should disable .js caching on both process and kernel caching from the cloud.
这应该会禁用来自云的进程和内核缓存上的 .js 缓存。
I thinkyou can create this web.config in a folder that contains just your file and it will disable caching for .js only at that folder level. I honestly have not tried that myself, so just a suggestion you could test.
我认为您可以在仅包含您的文件的文件夹中创建此 web.config,它将仅在该文件夹级别禁用 .js 缓存。老实说,我自己还没有尝试过,所以只是一个你可以测试的建议。
Beyond that, take a look at the documentation for IIS related to caching config:
除此之外,请查看与缓存配置相关的 IIS 文档:
/Caching: http://www.iis.net/ConfigReference/system.webServer/caching
/缓存:http: //www.iis.net/ConfigReference/system.webServer/caching
/Caching/Profiles: http://www.iis.net/ConfigReference/system.webServer/caching/profiles
/缓存/配置文件:http: //www.iis.net/ConfigReference/system.webServer/caching/profiles
/Caching/Profiles/Add: http://www.iis.net/ConfigReference/system.webServer/caching/profiles/add
/缓存/配置文件/添加:http: //www.iis.net/ConfigReference/system.webServer/caching/profiles/add
Hopefully that, plus some research on those config tags will help.
希望这一点,加上对这些配置标签的一些研究会有所帮助。
If not, I'd recommend looking into implementing a custom HTTP Module that you can insert into the IIS request pipe, which can filter your caching control down to that particular file
如果没有,我建议您考虑实现一个自定义 HTTP 模块,您可以将其插入到 IIS 请求管道中,它可以将您的缓存控制过滤到该特定文件
** for what its worth this is just IIS behavior and won't be different in or out of Azure, so you could easily test this local without bothering with the Dev fabric or Azure testing.
** 值得一提的是,这只是 IIS 行为,在 Azure 内外不会有所不同,因此您可以轻松地测试这个本地,而无需费心进行 Dev Fabric 或 Azure 测试。
回答by Martijn
You can disable output caching on folder level by removing an extension on folder level by including a web.config in that folder like this
您可以通过在该文件夹中包含一个 web.config 来删除文件夹级别的扩展,从而禁用文件夹级别的输出缓存
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<caching>
<profiles>
<remove extension=".js" />
</profiles>
</caching>
</system.webServer>
</configuration>
now this folder will not have output caching enabled for files ending with .js
现在此文件夹将不会为以 .js 结尾的文件启用输出缓存
回答by Rohit
Open IIS panel.
打开 IIS 面板。
Open the related application from sites, then navigate to folder containing particular file.
从站点打开相关应用程序,然后导航到包含特定文件的文件夹。
Now from right pane, switch to content view
现在从右窗格切换到内容视图
Select your desired file
选择你想要的文件
Now right click on file to choose "Switch to Feature View".
现在右键单击文件以选择“切换到功能视图”。
From there choose HTTP Response Headers, click "Add" to add new header, Add "Cache-Control" header with "no-cache" value.
从那里选择 HTTP 响应标头,单击“添加”以添加新标头,添加带有“no-cache”值的“Cache-Control”标头。
回答by jherax
Yes, it is possible, you can do it in the configuration file:
(See https://stackoverflow.com/a/4821328/2247494)
是的,有可能,您可以在配置文件中进行:(
参见https://stackoverflow.com/a/4821328/2247494)
<configuration>
<location path="cache.manifest">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>

