Why is Request not available for my PDF request?

Posted by Beska on Stack Overflow See other posts from Stack Overflow or by Beska
Published on 2010-06-11T16:50:09Z Indexed on 2010/06/11 16:52 UTC
Read the original article Hit count: 225

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET