I have an MVC app that displays a PDF from byte data being retrieved from the database, and the PDF renders just fine in my internet browser if my browser is pointed to "localhost". But, if I change "localhost" with my actual machine name, the PDF doesn't render. The app works exactly as I expect except for that. I have my site hosted in my local IIS, by the way (obviously).
The funny thing is when the PDF doesn't render, I can right click on the area where the PDF should render in and choose "Save As" and save the PDF to my computer, open it up, and it opens just fine.
Question: Can anyone offer any suggestions as to what might be causing the problem? Is "localhost" the exact equivalent to my machine name in all regards when it comes to IIS hosting?
I'm not sure if this even matters, but here's my code:
Controller Code
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 View
@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>