简体   繁体   English

ASP.NET-Window.Open(URL)-缓存了文件,如何停止它?

[英]ASP.NET - Window.Open(URL) - File is cached, how do I stop it?

I'm using ASP.NET to load PDFs. 我正在使用ASP.NET加载PDF。 The files are called by a simple JavaScript in the code behind: 这些文件由简单的JavaScript在后面的代码中调用:

ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", "window.open('" + url + "')", true);

Is there a way to prevent IE from caching these files? 有没有一种方法可以防止IE缓存这些文件? Maybe something to add to the endo f the JS to prevent caching? 也许要在JS的内部添加一些内容以防止缓存? Some files are modified based on user input, so the same file name may be a completely different file the next time the same URL is loaded. 有些文件是根据用户输入进行修改的,因此下一次加载相同的URL时,相同的文件名可能是完全不同的文件。

I've tried deleting the file before it is modified and saved, but that did not help. 我尝试过删除文件,然后再进行修改和保存,但这无济于事。 The only thing that helped was a manual refresh of the IE window once the PDF had loaded into it. 唯一有用的是将PDF加载到IE窗口后对其进行手动刷新。

Thanks! 谢谢!

Attach a random number to the querystring of the url. 在网址的查询字符串中附加一个随机数。 A date stamp is often used: 经常使用日期戳:

"window.open('"+url+"&_='+(new Date()).valueOf())"

Which will ensure that a cached copy is not retrieved (cache varies on querystring). 这将确保不检索缓存的副本(缓存因查询字符串而异)。

A common convention to avoid this problem with IE caching issues (if you don't want to modify the cache policy) is to append a random number (generated on the fly) to the end of the url as a querystring parameter. 避免此问题与IE缓存问题(如果您不想修改缓存策略)的常见约定是将随机数(即时生成)附加到url的末尾作为querystring参数。 This does not have to be read on the server, it just helps uniquely differentiate the url for the request. 不必在服务器上读取它,它仅有助于唯一地区分请求的URL。

ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", "window.open('" + url + "?random=' + Math.random())", true);
Response.Cache.SetExpires(-1);

在asp.net页面上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM