开发者

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

I'm using ASP.NET to load 开发者_如何学编程PDFs. The files are called by a simple JavaScript in the code behind:

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

Is there a way to prevent IE from caching these files? Maybe something to add to the endo f the JS to prevent caching? 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.

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.

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).


Response.Cache.SetExpires(-1);

on asp.net page


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. This does not have to be read on the server, it just helps uniquely differentiate the url for the request.

ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", "window.open('" + url + "?random=' + Math.random())", true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜