我最近遇到了一个问题,想要返回PDF内联响应。我在所有可用的编码页面上进行了搜索,但仍然无法找到适用于此问题的答案。下面是我制作的一个简化示例,但核心部分与实际生产环境相同。虽然这个问题并不总是发生,但当它发生时非常恼人。似乎像是某种奇怪的时间问题或者其他一些我没有看到的问题。
我收到了这个错误信息:System.Web.HttpException (0x80004005): File Not Found ---> System.Web.HttpException (0x80004005): Server cannot append header after HTTP headers have been sent.
有人知道如何解决吗?
我收到了这个错误信息:System.Web.HttpException (0x80004005): File Not Found ---> System.Web.HttpException (0x80004005): Server cannot append header after HTTP headers have been sent.
有人知道如何解决吗?
[HttpGet]
public ActionResult PDF(string id, bool inline = false)
{
try
{
MemoryStream PDFStream = GetPdfStream(id);
PDFStream.Position = 0;
string PDFFile = "Test.pdf";
if (inline)
{
Response.AppendHeader("Content-Disposition", string.Format("inline; filename={0}", PDFFile));
Response.BufferOutput = true;
return File(PDFStream, MediaTypeNames.Application.Pdf);
}
else
return File(PDFStream, MediaTypeNames.Application.Pdf, PDFFile);
}
catch (Exception Ex)
{
throw new HttpException(404, "File Not Found", Ex);
}
}