【发布时间】:2015-10-06 00:26:26
【问题描述】:
我创建了一个方法,用于创建 pdf 并将其保存到项目中的目录中。但是,我无法在创建此文件后下载该文件。我已经尝试了几个我在堆栈溢出和许多其他站点上看到的选项。我可以在 firebug 的响应中看到 PDF 内容,我可以手动打开文件,但没有文件下载。请帮忙。
控制器
public class SignatureController : Controller
{
// GET: Signature
public FileContentResult Index(string orderNumber)
{
var pdfFile = DocumentGenerator.GenerateSignedDocument(orderNumber);
byte[] filedata = System.IO.File.ReadAllBytes(pdfFile);
string contentType = MimeMapping.GetMimeMapping(pdfFile);
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
{
FileName = pdfFile,
Inline = true,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(filedata, contentType);
}
}
PDF 生成器
public static string GenerateSignedDocument(string orderNumber)
{
...............
string currentDate = DateTime.Now.ToString("MMddyyyy");
string fileName = HostingEnvironment.MapPath(pdfTempPath) + orderNumber + currentDate + ".pdf";
pdfDocument.Save(fileName);
return fileName;
}
标题正在返回
缓存控制
私人的
内容处置
附件;文件名="签名文件.pdf"
内容编码
压缩包
内容类型
申请/pdf
日期
格林威治标准时间 2015 年 7 月 16 日星期四 16:58:29
服务器
微软-IIS/8.0
传输编码
分块
变化
接受编码
X-AspNet-版本
4.0.30319
X-AspNetMvc-版本
5.2
X-Powered-By
ASP.NET
X-SourceFiles
=?UTF-8?B?QzpcVXNlcnNccmphbWVzXFNvdXJjZVxXb3Jrc3BhY2VzXEN1c3RvbWVyUGlja1VwXEN1c3RvbWVyUGlja1VwLldlYlxTaWduYXR1cmVcSW5kZXg
=?=
【问题讨论】:
标签: asp.net-mvc-4 pdf iis