下載代碼是需要設置 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(); }