简体   繁体   中英

Query string in Content-Disposition header

I'm downloading a file with Response.WriteFile and appending a timestamp to the filename in order to prevent IE from caching the downloaded file. But the browser is changing ? to _ .

string filePath = Server.MapPath("~/test.docx");
string fileName = string.Concat("test.docx", "?t=", DateTime.Now.Ticks);
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.WriteFile(filePath);
...

Expected result: test.docx

Actual result: test.docx_t=635823369853307954

Is this possible?

Browser will eventually cache result according to requested url (and other headers), not to filename attribute in "content-disposition" response header.

The latter is known to the brower only after he decided to call again the web server and got a response: if it has already decided to use the cache, it will not send any new request to server.

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