0

I am using HttpHandler to retrieve image from database and then use the Handler as ImageUrl in an Image web control on my web page (aspx). The code is shown below. But it does not work and so far I could not figure out why. The issue is HttpHandler is never been hit, if I keep the breakpoint at processrequest() it is never hit

Below is the simple code in Handler

public class ImageHandler : IHttpHandler
{
    StaffMemberRepository db = new StaffMemberRepository();
    public void ProcessRequest(HttpContext context)
    {
        int id = Convert.ToInt32(context.Request.QueryString["id"].ToString());
        byte[] image = db.GetImage(id);
        context.Response.ContentType = "image/jpg";
        context.Response.BinaryWrite(image);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

and below is the markup in my webpage

asp:Image ID="imgStaff" runat="server" ImageAlign="Middle" ImageUrl="~/Handlers/ImageHandler.ashx?id=2"

Can someone let me know what I am doing wrong here?

j.w.r
  • 4,136
  • 2
  • 27
  • 29
  • Could you provide the web config section where you register your handler? – Josh Sep 05 '12 at 20:23
  • Have you pointed your browser to this: Handlers/ImageHandler.ashx?id=2 ? – Jack Marchetti Sep 05 '12 at 20:24
  • I did not put anything in Web.config yet. I might be thinking foolishly but I thought as far as I am using ASP DEV server for my local machine I can skip the web.config part. Kindly correct me if that is not the case. – sherebiah.tishbi Sep 05 '12 at 20:41
  • @Jack - in the markup code I have pasted you can see that Imageurl is pointing to ~/Handlers/ImageHandler.ashx?id=2. – sherebiah.tishbi Sep 05 '12 at 20:42

1 Answers1

0

Ok I could see my folly now. I just registered my handler in web.config and everything seems ok now.