C# 使用IE下载文件总是下载HTML代码

来源:互联网 发布:java运行环境下载 编辑:程序博客网 时间:2024/05/22 02:31

这个不是代码的问题,在360浏览器上就能正常下载。下面是我下载使用的代码

   #region 下载文件

//DESPath是物理路径
        FileInfo fileInfo = new FileInfo(DESPath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=config.sida");
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();
     #endregion


解决方法:

在网上找到这个帖子
https://zhidao.baidu.com/question/508228124.html

里面有提到可能是应为使用了迅雷下载了,这和我的情况一致。设置迅雷不检测浏览器的下载,使用网页下载,我的问题就解决了。当然最好在测试前清理一下浏览器的缓存。


0 0
原创粉丝点击