1

当我进行此调用时,它会返回内容、正确的 mime 类型和文件名。它只是不会下载。

如果有人对如何解决此问题有任何想法,我们将不胜感激。

public FileResult Download()
{
  if (HelperClass.SessionNotExpired(Session))
  {
    string caseNumber = Request.Params["CaseNumber"] as string;
    string fileName = Request.Params["FileName"] as string;
    if (!String.IsNullOrEmpty(caseNumber) && !String.IsNullOrEmpty(fileName))
    {
      Document doc = DropBox.Get(caseNumber, fileName, DocumentServiceRequestCodes.WEB,          (string)Session[HelperClass.EMAIL], (string)Session[HelperClass.PASSWORD]);
      var cd = new System.Net.Mime.ContentDisposition
      {
        // for example foo.bak
        FileName = doc.FileName,

        // always prompt the user for downloading, set to true if you want 
        // the browser to try to show the file inline
        Inline = false,
      };
      Response.AppendHeader("Content-Disposition", cd.ToString());

      return File(doc.Contents, GetMimeType(fileName), fileName);
    }
  }
  return null;
}
4

1 回答 1

0

如果内容是流尝试手动设置其位置?

stream.Seek(0, SeekOrigin.Begin);

或者

stream.Position = 0;

于 2014-02-18T05:35:00.883 回答