title: How do I use an .ashx handler with an asp:Image object?
body: <p>I have an ashx handler:</p>
  
  <pre><code>&lt;%@ WebHandler Language="C#" Class="Thumbnail" %&gt;
  
  using System;
  using System.Web;
  
  public class Thumbnail : IHttpHandler
  {
  
      public void ProcessRequest(HttpContext context)
      {
          string imagePath = context.Request.QueryString["image"];
  
          // split the string on periods and read the last element, this is to ensure we have
          // the right ContentType if the file is named something like "image1.jpg.png"
          string[] imageArray = imagePath.Split('.');
  
          if (imageArray.Length &lt;= 1)
          {
              throw new HttpException(404, "Invalid photo name.");
          }
          else
          {
              context.Response.ContentType = "image/" + imageArray[imageArray.Length - 1];
              context.Response.Write(imagePath);
          }
      }
  
      public bool IsReusable
      {
          get { return true; }
      }
  }
  </code></pre>
  
  <p>For now all this handler does is get an image and return it. In my aspx page, I have this line:</p>
  
  <pre><code>&lt;asp:Image ID="Image1" runat="server" CssClass="thumbnail" /&gt;
  </code></pre>
  
  <p>And the C# code behind it is:</p>
  
  <pre><code>Image1.ImageUrl = "Thumbnail.ashx?image=../Files/random guid string/test.jpg";
  </code></pre>
  
  <p>When I view the web page, the images are not showing and the HTML shows exactly what I typed:</p>
  
  <pre><code>&lt;img class="thumbnail" src="Thumbnail.ashx?image=../Files%5Crandom guid string%5Cimages%5Ctest.jpg" style="border-width:0px;" /&gt;
  </code></pre>
  
  <p>Can someone tell me why this isn't working? Unfortunately I only started working with ASP.NET yesterday and I have no idea how it works, so please keep the explanations simple if possible, thanks.</p>