下载文档时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