首页 新闻 赞助 找找看

.NET 迅雷下载 是成页面,浏览器自带没有问题

0
悬赏园豆:20 [已解决问题] 解决于 2015-04-14 10:41
 1  string fileName = strname;//客户端保存的文件名  我最红.mp3
 2             string filePath = Server.MapPath(strfilepath);//路径
 3 
 4 
 5             //FileInfo fl = new FileInfo(filePath);
 6             FileStream fs = new FileStream(filePath, FileMode.Open);
 7 
 8             byte[] bytes = new byte[(int)fs.Length];
 9             fs.Read(bytes, 0, bytes.Length);
10             fs.Close();
11             Response.ContentType = "application/octet-stream";
12             Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
13 
14 
15             //filePath = "AA" + filePath + "ZZ";
16             //string encode = "";
17             //byte[] bytes = Encoding.GetEncoding(54936).GetBytes(filePath);
18             //try
19             //{
20             //    encode = Convert.ToBase64String(bytes);
21             //}
22             //catch
23             //{
24             //    encode = filePath;
25             //}
26             
27            // Response.AddHeader("Content-Disposition", String.Format("attachment;filename=" + fileName));
28            // Response.AppendHeader("Content-Length", fl.Length.ToString());
29             //Response.ContentEncoding = System.Text.Encoding.Default;
30             //Response.ContentType = "application/octet-stream";
31 
32             //Response.WriteFile(filePath);
33             //Response.Redirect("thunder://" + encode);
34            
35             Response.BinaryWrite(bytes);
36             Response.Flush();
37             Response.End();

也用了网上找的几种办法,但是还是不能用迅雷下载,包括改成迅雷的地址格式。

最先用的是文件流格式的,用这种办法浏览器自带的下载器没问题,第二总用的是

Response.WriteFile(filePath)也是浏览器没问题,迅雷不可以。
第三种
Redirect 跳转总是失败

门前有根大呲花的主页 门前有根大呲花 | 初学一级 | 园豆:149
提问于:2015-04-13 15:20
< >
分享
最佳答案
0

http://q.cnblogs.com/q/40757/

收获园豆:10
问天何必 | 老鸟四级 |园豆:3311 | 2015-04-13 16:31

除了续传的实现的原理是一样的,没看出来有什么区别,我回去在用自己的电脑实验一下

门前有根大呲花 | 园豆:149 (初学一级) | 2015-04-13 17:33
其他回答(1)
0

如果你链接的后缀名不是主流格式,即不是 .asp .aspx .html等。

这个在IIS里面设置,处理程序映射,具体设置我说不清楚。

大体设置是告诉你的IIS后缀名为 .*** 的文件当成网页脚本处理,这样这个页面就不会被下载工具下载到了。

收获园豆:10
中国博客玩家 | 园豆:234 (菜鸟二级) | 2015-04-13 17:33

这个本地localhost:运行的,我在在我自己的电脑上实验一下吧

支持(0) 反对(0) 门前有根大呲花 | 园豆:149 (初学一级) | 2015-04-13 20:10

 Response.Redirect(String.Format( "~/files/{0}",fileName),false);

用这个跳转是可以用迅雷下载了,但是这个把文件的地址什么的全都显露出来了,为什么用文件流不行呢

支持(0) 反对(0) 门前有根大呲花 | 园豆:149 (初学一级) | 2015-04-13 20:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册