简体   繁体   中英

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

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);
Response.Cache.SetExpires(-1);

在asp.net页面上

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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