0

我正在使用以下代码下载文件,下载文件后它会打开我的网站页面,但它只能在 Firefox 浏览器中工作。它不适用于其他浏览器。

Response.AddHeader("Refresh", "3; url=http://www.mysite.com/");
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=myfile.pdf");
Response.TransmitFile(Server.MapPath("myfile.pdf"));
Response.End();
4

3 回答 3

1

您不能可靠地跨浏览器将文件推送到客户端,然后在一个 HTTP 响应中重定向。

只需创建一个显示您想要显示的内容的登录页面,然后让该页面(重定向到)下载。

于 2013-09-25T12:52:56.480 回答
0

使用此代码

Response.ClearContent();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
于 2013-09-25T12:12:28.503 回答
0

我确实偶然发现了“使用双引号,因此文件名中带有逗号的文档在 Chrome Response.AddHeader("Content-Disposition", "attachment;filename=""" + myfile.Filnavn & "") 中是可以的

Chrome可能需要双引号

于 2016-03-02T12:57:42.800 回答