下載文檔時Safari瀏覽器下載后出現".html"問題


下載代碼是需要設置 Response.ContentType = "application/octet-stream",

不要設為application/x-msdownload,改設為applicatoin/octet-stream即可(這種格式代表任意的二進制數據),

ContentType用於定義用戶的瀏覽器或相關設備如何顯示將要加載的數據。

 代碼如下:

        private static void RenderToBrowser(byte[] bytes, HttpContext context, string downloadname)
        {
            if (context.Request.Browser.Browser == "IE")
            {
                downloadname = HttpUtility.UrlEncode(downloadname, System.Text.Encoding.UTF8).Replace("+", "%20");
            }
            context.Response.ContentType = "application/octet-stream";
            context.Response.AddHeader("Content-Disposition", "attachment;fileName=" + downloadname);
            context.Response.BinaryWrite(bytes);
            context.Response.Flush();
            context.Response.End();
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM