【发布时间】:2013-06-14 22:03:01
【问题描述】:
我有一个 MVC 应用程序,它显示从数据库中检索的字节数据的 PDF,如果我的浏览器指向“localhost”,PDF 在我的互联网浏览器中呈现得很好。但是,如果我用我的实际机器名称更改“localhost”,则 PDF 不会呈现。该应用程序完全按照我的预期工作,除了这一点。顺便说一下(显然),我的网站托管在本地 IIS 中。
有趣的是,当 PDF 不呈现时,我可以右键单击 PDF 应该呈现的区域并选择“另存为”并将 PDF 保存到我的计算机,打开它,它只是打开美好的。
问题:任何人都可以就可能导致问题的原因提供任何建议吗?在 IIS 托管方面,“localhost”是否完全等同于我的机器名称?
我不确定这是否重要,但这是我的代码:
控制器代码
public FileStreamResult PdfGenerator(string id)
{
Stream fileStream = GeneratePdf(id);
HttpContext.Response.AddHeader("content-disposition", "attachment; filename=form.pdf");
return new FileStreamResult(fileStream, "application/pdf");
}
public Stream GeneratePdf(string id)
{
// get and return the PDF byte data
byte[] pdf = (from i in db.Pictures where i.GroupId == id && i.blah== "YES" select i.pdf).FirstOrDefault();
Stream pdfStream = new MemoryStream(pdf);
return pdfStream;
}
public ActionResult DisplayPdf(string id)
{
Picture picture = (from i in db.Pictures where i.GroupId == id && i.blah== "YES" select i).FirstOrDefault();
return View(picture);
}
DisplayPdf 视图
@model blah.Models.Picture
<object
data="@Url.Action("PdfGenerator", "ImageViewer", new { id = Model.GroupId })"
type="application/pdf"
width="640"
height="480">
<param value="transparent" name="wmode"/>
</object>
【问题讨论】:
-
+1 只是为了我见过的最长的标题! :)
-
@Liam 我还有很多其他标题很长的问题,请随意投票,:) 哈哈
-
我不确定,我会假设在涉及 IIS 时,“localhost”在所有方面都等同于我的机器名称......不过我可能是错的。
-
不,忘记了,说它不适用于
object -
当您浏览到 url 时会发生什么?有用吗?
标签: c# asp.net-mvc pdf render