I am trying to code a simple handler that should return an image URL so that I can display it on my website. This is how my handler looks like:
<%@ WebHandler Language="C#" Class="KameraHandler" %>
using System;
using System.Web;
public class KameraHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.Write("http://web.scott.k12.va.us/martha2/dmbtest.gif");
}
public bool IsReusable {
get {
return false;
}
}
}
and this is how I call my handler but It just doesn' work.
protected void AraLinkButton_Click(object sender, EventArgs e)
{
KameraImage.Src = "~/GenericHandler/KameraHandler.ashx;
}
Your image handler is supposed to return the raw bytes of an image (and with the appropriate Content-Type
), not the URL of an image.
You should set the src
directly to that (external) URL.
Alternatively, you could make your ASHX send a redirect to that URL, or make it forward the contents of that URL.