下载文档时Safari浏览器下载后出现".html"问题
2015-11-11 19:10 神话哥 阅读(2861) 评论(0) 编辑 收藏 举报下载代码是需要设置 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(); }