以编程方式使 Silverlight XAP 文件从浏览器缓存中过期
如何防止 Web 浏览器缓存 Silverlight XAP 文件?
我想这样做的原因是在开发过程中我不想手动清除浏览器缓存,我正在寻找服务器端的编程方法。
How to do I prevent a Silverlight XAP file being cached by the web browser?
The reason I want to do this is during development I don't want to manually clear the browser cache, I'm looking for a programmatic approach server side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用 IIS 管理添加自定义标头
Cache-Control
,其值为no-cache
。这将导致浏览器在使用之前检查 XAP 的任何缓存版本是否是最新的。Using IIS management add a custom header
Cache-Control
with the valueno-cache
. That'll cause the browser to check that any cached version of the XAP is the latest before using it.将查询参数添加到 HTML 页面上元素中 XAP 的 URL:
它将被忽略并破坏缓存。
在IE8中,有一些缓存管理工具:
打开开发人员工具:
Add a query parameter to the URL for the XAP in the element on the HTML Page:
It will be ignored and break the cache.
In IE8, there are some cache management tools:
Open the Developer tools:
此处提出的解决方案有些相似迈克尔的,但它是自动的,并保证客户总是会得到新版本。根据您的具体情况,这可能效率较低。
由于 Lars 在他的 评论中表示他不参与Stack Overflow,我在这里复制回复。
The solution presented here is somewhat similar to Michael's but is automatic and guarantees the client will always get a new version. This may be inefficient depending on your situation.
Since Lars says in his comments that he is not on Stack Overflow, I'm copying the response here.
创建一个自定义 http 处理程序来处理 *.xap 文件,然后在处理程序内设置缓存选项。
像这样的东西...
Create a custom http handler for handling *.xap files and then set your caching options inside the handler.
Something like this...
我在 xap 文件的路径中添加了一个查询参数,以便我可以通过版本控制来管理它。
Default.aspx 代码:
Default.aspx.cs 代码:
I added a query parm to the path of the xap file, so that I can manage it through Versioning.
Default.aspx code:
Default.aspx.cs code:
好吧,以上所有示例都依赖于浏览器不缓存包含新技巧 xap 名称的 HTML...,因此您只需将问题转移到其他问题上即可。
而且它们也极其复杂......
但是对于调试情况,至少,很容易编写
这避免了您在控制服务器设置时可能遇到的任何麻烦,并且无论使用何种服务器技术,都可以正常工作。
注意:您必须使用相同的方法编写整个对象组,因为将脚本标记放入对象标记中意味着“仅在浏览器不支持该对象时才执行此操作。
Well all the above examples depend on the browser NOT caching the HTML that contains the new trick xap name.... so you just move the problem on to something else.
And they are also fiendishly complicated....
However for the debugging case, at least, it's easy to write the <object> and <param> tags in javascript so that the name changes every time the html page is used, whether it's cached by the browser or not!
This sidesteps any hassle you may have controlling server settings and works just as well regardless of the server technology in use.
Note: you have to write the whole object group with the same method because putting a script tag inside the object tag means "only do this if the browser doesnt support the object.
遇到 .XAP 缓存的情况并不少见,这意味着每次部署新版本的 Silverlight 应用程序时,浏览器都不会下载更新的 .XAP 文件。
一种解决方案是更改 IIS 属性。您可以按照以下步骤为您的 .XAP 文件打开“启用内容过期 HTTP 标头”选项:
这样,当您刷新页面时,就会下载最新的 .XAP(仅当有最新的 .XAP 文件时),而无需关闭浏览器。
希望这有帮助!
It’s not very uncommon to run into .XAP caching, which means that every time you deploy a new version of the Silverlight application, the browser does not download the updated .XAP file.
One solution could be to change the IIS properties. You can turn the “Enable Content Expiration HTTP header” option on for your .XAP file by following these step:
This way the latest .XAP (only if there is a latest .XAP file) will get downloaded when you refresh your page without having to close the browser.
Hope this helps!