我有一个关于我正在寻找的东西的问题…太久了!我们已经构建了一个应用程序,管理员可以从该应用程序将歌曲上载到数据库中。然后用户可以购买歌曲并单独下载。问题是,当用户用下面的代码下载MP3歌曲时,它在Firefox和Chrome中很好地工作,但在IE8中却不是这样,因为WMP试图打开歌曲,但它只是没有得到它,而没有“另存为”对话框?关于如何强制使用“另存为”诊断日志的任何问题?请注意,服务器上没有MP3物理测试,它在数据库中。所以我不能直接链接到歌曲…
这是我的代码:
// Remove "specials chars"
foreach (char aChar in @"/\:*?""<>| ") {
if (aChar == ' ') {
songNameAndExt = songNameAndExt.Replace(' ', '_');
} else {
songNameAndExt = songNameAndExt.Replace(aChar.ToString(), string.Empty);
}
}
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.Headers.Add("Content-Disposition", string.Format("filename={0}", songNameAndExt));
HttpContext.Current.Response.OutputStream.Write(songData, 0, songLength);