I've created code to retrieve an image from the file system using an ASHX handler. The code displays the image correctly in Chrome, but I get a broken image in IE:
public class ImageHandler : IHttpHandler
{
private int? QS_ImageID
{
get
{
int? temp = null;
if (HttpContext.Current.Request.QueryString["ImageID"] != null)
temp = HA.Utility.DataHelper.ParseDbInt(HttpContext.Current.Request.QueryString["ImageID"]);
return temp;
}
}
private bool QS_Thumbnail
{
get
{
bool thumbNail = false;
if (HttpContext.Current.Request.QueryString["Thumbnail"] != null)
{
if (HttpContext.Current.Request.QueryString["Thumbnail"].Equals("1"))
thumbNail = true;
}
return thumbNail;
}
}
public void ProcessRequest(HttpContext context)
{
if (QS_ImageID.HasValue)
{
int uploadID = QS_ImageID.Value;
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.Cache.SetNoStore();
context.Response.ContentType = UploadDAL.GetMetaData(uploadID).UploadContentType;
context.Response.AddHeader("Content-Disposition", "inline;");
if (QS_Thumbnail)
{
byte[] myImage = UploadDAL.GetFileThumbNail(uploadID);
context.Response.AddHeader("Content-Length", myImage.GetLength(0).ToString());
context.Response.BinaryWrite(myImage);
context.Response.End();
}
else
{
byte[] myImage = UploadDAL.GetFile(uploadID);
context.Response.AddHeader("Content-Length", myImage.GetLength(0).ToString());
context.Response.BinaryWrite(myImage);
context.Response.End();
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}