.ashx image handler
I am attempting to implement a .ashx handler to serve images to the src attribute of image tags within my site;
<img src="contentHandler.ashx?image=testimage.jpg" />
The following code in the contentHandler.ashx file works fine in a plain .net site;
public void ProcessRequest (HttpContext context)
HttpResponse r = context.Response;
r.ContentType = "image/jpg";
imageName = context.Request.QueryString["image"];
if (imageName != "")
r.WriteFile("~/Images/" + imageName);
However, it seems Sitefinitys use of virtual paths for images conflicts with this and i cannot identify the appropriate path string to serve the image.
I have tried numerous variations of image paths, with and without ~ and /images etc and I have also used the libraries manager to access the image file path from the id.
Thus far the system error with either, not a valid virtual path, virtual path not allowed here or it tries to get the image from a path with C drive as the root
not the app.
Can anyone assist here?
Thanks
Dan.