簡體   English   中英

Response.AddHeader在Chrome和Safari瀏覽器中不起作用

[英]Response.AddHeader is not working in Chrome and Safari Browsers

我正在使用以下代碼下載文件,下載文件后打開了我的網站頁面,但僅在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();

您無法可靠地跨瀏覽器將文件推送到客戶端,然后在一個HTTP響應中重定向。

只需創建一個顯示您要顯示的內容的登錄頁面,然后下載該頁面(重定向到該頁面)即可。

使用此代碼

Response.ClearContent();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";

我確實偶然發現了“使用雙引號,因此在Chrome Response.AddHeader(“ Content-Disposition”,“ attachment; filename =”“” + myfile.Filnavn&“”)中文件名中帶有逗號的文檔就可以了。

Chrome可能需要使用雙引號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM