We're trying to create a .NET aspx page that will have a PDF within it. Doing this by hardcoding it is easy.
<object height="1250px" width="100%" type="application/pdf" data="our.pdf">
<param value="our.pdf" name="src" />
<param value="transparent" name="wmode" />
</object>
(don't worry too much about the transparent thing...we're doing that for other reasons...but I include it here "just in case".)
The problem is when we want to generate the PDF dynamically. Our code to populate the literal on the front end looks like this:
ltrPDF.Text = String.Format("<object height=\"1250px\" width=\"100%\" type=\"application/pdf\" data=\"ourPdfGenerator.aspx?var0={0}&var1={1}&var2={2}\">", var0, var1, var2);
ltrPDF.Text += String.Format("<param value=\"ourPdfGenerator.aspx?var0={0}&var1={1}&var2={2}\">", var0, var1, var2);
ltrPDF.Text += "<param value=\"transparent\" name=\"wmode\"/>";
ltrPDF.Text += "</object>";
Kind of ugly, but it seems like it should work. But it doesn't.
When I debug, and put a breakpoint on the first line of ourPdfGenerator.aspx.cs Page_Load method, I reach the breakpoint without any difficulty. However, the first thing we do is try to use Request.QueryString:
string var0 = Request.QueryString["var0"];
which immediately throws an HttpException: "Request is not available in this context." I'm not clear on:
- Why isn't it available?
- What can I do about it?
EDIT: (as an aside, I know it seems a bit weird to ask for a mime-type of pdf from a aspx page...but we've used an aspx page to generate cs pages before...we do something like this:
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=\"our.pdf\"");
using (MemoryStream pdfStream = new MemoryStream())
{
ourSpecialPdfGenerator.ExportToPdf(pdfStream);
Response.BinaryWrite(pdfStream.ToArray());
}
Response.End();
And this has been working fine in other contexts for a while...but always as its own page. What we're doing differently now is instead of having this page called directly, we're trying to embed it, so it's being called from the <object>
tag, which is apparently causing problems...