Last post Aug 18, 2007 11:06 PM by StevenSw
Aug 14, 2007 01:24 PM|lilconnorpeterson|LINK
Im wondering if anyone has any suggestions for the following scenario:
An application we are working on "leeches" images from another web site (the other web site is also ours, we just dont need multiple copies our product catalog spread over every server). Occasionally we point to an image that does not exist (html from "New
Site" references "http://oldsite/product123.jpg).
Is there a way, using an httphandler or module (or any other way) to work around this? For instance, could I point to http://NewSite/ImagePage.ashx?imagename=http://oldsite/product123.jpg and somehow determine if the image exists, and if so send it to the
client and if not send a generic "not found" image?
Thanks for any ideas or suggestions.
Aug 16, 2007 09:40 AM|StevenSw|LINK
Maybe create a common web (virtual) to hold these images and each website could then point to a single common location. This was you can share images without the use of a handler. Just a thought.
Aug 16, 2007 10:52 PM|lilconnorpeterson|LINK
That's definately an idea worth trying, and something we have discussed implementing down the road.
Here's what I ended up with for my handler (rough draft version)
public class ImageLeechHandler : IHttpHandler
public void ProcessRequest(HttpContext context)
context.Response.ContentType = "image/jpg";
System.Net.WebClient client = new System.Net.WebClient();
byte image = null;
string imageURL = context.Request.QueryString;
image = client.DownloadData(imageURL);
image = client.DownloadData("http://url.to.an.image.that.says.404.sorry");
public bool IsReusable
And heres what I added to the config file to wire it together
<add verb="*" path="image.handler" type="ProjectBase.Demo.ImageLeechHandler, ProjectBase.Demo"/>
Aug 18, 2007 11:06 PM|StevenSw|LINK
Hmm how about extending this to:
HttpRequest httpRequest = context.Request;
string physicalPath = httpRequest.PhysicalPath;
string imageType = string.Empty;
string contentType = string.Empty;
string requestUrl = httpRequest.Url.Host;
string referrerUrl = httpRequest.UrlReferrer.Host;
if (string.Compare(requestUrl, referrerUrl) != 0)
physicalPath = context.Server.MapPath("~/stop.gif");