再问:我想用Response.WriteFile();防盗链播放MP3,为什么每次运行都弹出提示打开或者保存,而不能直接播放

gasover 2003-10-17 09:31:49
这个问题的我上一个帖子: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();
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
eagle_hb 2003-10-19
  • 打赏
  • 举报
回复
MP3收集
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();
xingzhi 2003-10-17
  • 打赏
  • 举报
回复
"Content-disposition",attachment;参数强制文件必须保存,你可以取消它。
gasover 2003-10-17
  • 打赏
  • 举报
回复
转向不就暴露 mp3 地址了吗, 而且我不打算给放歌那个文件夹启动iis服务,让它和internet 分离
rgbcn 2003-10-17
  • 打赏
  • 举报
回复
你用转向语句试试。
rgbcn 2003-10-17
  • 打赏
  • 举报
回复
不能这样写,
这样写,不管什么类型的文件,
都会以下载的形式出现

62,047

社区成员

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

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

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

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