title: How to Load dynamic Image from httpHandlers in C#
body: <p>I've got an ASP.NET application with a library that generates an Image. It is set up as follows:</p>
  
  <p>In the Web.config I have a declaration in the <strong>&lt;httpHandlers&gt;</strong> section like so:</p>
  
  <pre><code>&lt;add path="My.image.aspx" verb="GET" type="MyProject.Handlers.MyImageHandler, MyProject" validate="false"/&gt;
  </code></pre>
  
  <p>This links up the code to generate the image to that path which is then used on my .aspx page like this:</p>
  
  <pre><code>&lt;asp:Image ImageUrl="My.image.aspx" BorderWidth="0" ID="myImage" runat="server"/&gt;
  </code></pre>
  
  <p>When viewing this page normally, the image is loaded correctly.</p>
  
  <p>However, I need to output this image to a PDF file, but because the PDF's won't interpret the page HTML with that URL correctly (says it cannot find resource, because these files are limited to interpreting only basic HTML/CSS), I wanted to try to load the Image in the code behind and output it to the PDF that way. However, I have no idea how to load this image in the code behind. I tried the following:</p>
  
  <pre><code>System.Drawing.Image img = System.Drawing.Image.FromFile("My.image.aspx");
  </code></pre>
  
  <p>But had no luck. Is there a proper way to load this Image in the code behind from the httpHandler I have specified?</p>
  
  <p><strong>EDIT:</strong> I found a workaround, as I couldn't get the Image to load from the code behind. Instead, I have just used the &lt;asp:Image&gt; control to the load the file on the page and trigger the handler. When the handler creates the System.Drawing.Image file I was able to add it to the Session object for use later on that page. However, I still was unable to find a way to trigger all of that from the code behind without using a front end ASP control.</p>