2010-06-09 25 views
0

我對我正在搜索的內容有疑問,...太久了!我們構建了一個應用程序,管理員可以將歌曲上傳到數據庫中。然後用戶可以購買歌曲並單獨下載。問題是,當用戶使用下面的代碼下載MP3歌曲時,它在Firefox和Chrome中運行良好,但在IE8中卻不行,只是因爲WMP嘗試打開歌曲,而沒有得到它而不是「另存爲」對話框?關於HOW的任何問題,我可以強制將「另存爲」diaglog?請注意,我的數據庫中沒有裝有服務器的MP3。所以我不能直接鏈接到歌曲....MP3在HTTP響應中下載

這裏是我的代碼:

  // 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); 

回答

5

將其更改爲

HttpContext.Current.Response.Headers.Add("Content-Disposition", string.Format("attachment; filename={0}.mp3", songNameAndExt)) 
+0

完美!謝謝你SLaks!真的,你讓我節省了很多時間尋找不容易在搜索引擎搜索的東西!再次感謝你! – 2010-06-09 18:38:04