思归大哥帮帮我啊,我请你听歌~~~

gasover 2003-10-17 10:19:00
我想用Response.WriteFile();防盗链播放MP3,为什么每次运行都弹出提示打开或者保存,而不能直接播放
这个问题的我上一个帖子:http://expert.csdn.net/Expert/topic/2365/2365649.xml?temp=.7590601

每次弹出一个文件下载对话框,让我打开,保存,或者取消。
而我在网页上直接打开一个http的mp3地址,都可以直接播放的。

我的代码是这样写的,请指点:

FileInfo file = new System.IO.FileInfo("E:\\Songs\\apengyouzaijia.rm");

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";


Response.WriteFile(file.FullName);

Response.End();

...全文
84 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyover 2003-10-18
  • 打赏
  • 举报
回复
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

这行干掉。
gasover 2003-10-18
  • 打赏
  • 举报
回复
哈哈,解决了
gasover 2003-10-18
  • 打赏
  • 举报
回复
FileInfo file = new System.IO.FileInfo("E:\\煤炭网程序\\Songs\\apengyouzaijia.rm");

// clear the current output content from the buffer
Response.Clear();
// add the header that specifies
Response.AddHeader("Content-Disposition", "filename=" + file.Name);
// add the header that specifies the file size, so that the browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by the
// client and must be downloaded

string fileName = file.Name.ToLower();
int lastIndex = fileName.LastIndexOf(".");
fileName = fileName.Substring(lastIndex);

// 根据文件后缀指定文件的Mime类型
switch (fileName)
{
case ".rm":
Response.ContentType = "application/vnd.rn-realmedia";
break;
case ".mp3":
Response.ContentType = "audio/mpeg3";
break;
case ".asf":
Response.ContentType = "video/x-ms-asf";
break;
case ".avi":
Response.ContentType = "video/avi";
break;
case ".wav":
Response.ContentType = "audio/wav";
break;
case ".mpg":
Response.ContentType = "video/mpeg";
break;
case "mpeg":
Response.ContentType = "video/mpeg";
break;
default:
Response.ContentType = "application/octet-stream";
break;
}

// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();
saucer 2003-10-17
  • 打赏
  • 举报
回复
Response.Clear();
...
Response.End();
gasover 2003-10-17
  • 打赏
  • 举报
回复
还是不行,思归大哥,要么页面显示一对乱码,要么还是提示下载,
还是听歌吧 最近被我女孩拒绝了,喜欢听这首歌http://www.paifang.com/go/mm/mtv0203.rm
saucer 2003-10-17
  • 打赏
  • 举报
回复
you are sending the wrong content-type, try

ContentType="audio/x-pn-realaudio"

or

application/vnd.rn-realmedia

see others at
http://service.real.com/help/faq/rp8/configrp8win.html
gasover 2003-10-17
  • 打赏
  • 举报
回复
是啊,连 .aspx 文件都会弹出下载窗口,请问有更好的解决方法吗?
rgbcn 2003-10-17
  • 打赏
  • 举报
回复
这样做好像什么文件都是可以下载的。
连text html 类型的文件都会是弹出下载的窗口.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧