我有电子商务网站并在其中上传了一些mp3文件,客户可以将mp3文件下载到PC上,但是当他们尝试将它们下载到iPad时,iPad无法下载它们。
下载文件的代码如下
public static void DownloadAudio(string url)
{
if (HttpContext.Current.CurrentHandler is basePage)
{
HttpContext.Current.Response.Clear();
string fileDiskPath = HttpContext.Current.Server.MapPath(url);
FileInfo fileInfo = new FileInfo(fileDiskPath);
HttpContext.Current.Response.ContentType = "audio/mp3";
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", fileInfo.Name));
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.WriteFile(fileDiskPath);
//HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
else
{
throw new NotSupportedException("Note: This method is not supporting user controls. Consider supporting user controls by getting the parent page from user control.");
}
}