I am creating a barcode image as a response from an HTTP handler, for example:
public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.ContentType = "image/Jpeg"; MemoryStream ms = new MemoryStream(); Bitmap objBitmap = GenerateBarcode(context.Request.Params["Code"]); objBitmap.Save(ms, ImageFormat.Jpeg); context.Response.BinaryWrite(ms.GetBuffer()); }
I go to http://www.MyWebsite.com/MyProject/BarCode.aspx?code=12345678 and it works fine. Similarly, I stick with <img alt="" src="http://www.MyWebsite.com/MyProject/BarCode.aspx?code=12345678"> on my web page, and it works great. But I stick to the same image tag in the HTML email and it does not appear (at least not in MS Outlook 2007, I have not tested other email clients yet.)
I suppose this has something to do with the fact that I am using an HTTP handler, as other static images in the email render well. How can I fix this so that the image appears? (I can't just use a static image because the code is detected when sending email.)
Update:
Turns out I didn't notice a key detail. The image is not just not displayed; rather, the src attribute of the image is replaced by " http://portal.mxlogic.com/images/transparent.gif ". I decided that using the .aspx or .ashx extensions would cause this replacement (or perhaps any extension, except for those expected for images like .gif or .jpg), and that including the query string in the URL would also cause this. even if it's a standard image extension. I assume this is an excessive security feature. Therefore including an image such as BarCode.aspx? Code = 12345678, just won't work.
It seems to me that I could do something like <img alt="" src="http://www.MyWebsite.com/MyProject/12345678/BarCode.jpg"> and then create a handler for all files with the name BarCode.jpg. Here 12345678 / is not the actual path, but that would not matter, as I redirect the request to the handler, and I could clear the code value from this logical path in the URL. But I probably have to change some IIS setting to have requests for .jpg files handled by ASP.NET, and I want it to still check that other JPEGs other than my BarCode.jpg load normally.
Honestly, I'm not sure if the hassle is worth it.
Tim goodman
source share