【发布时间】:2010-07-25 01:16:24
【问题描述】:
我创建了代码来使用 ASHX 处理程序从文件系统中检索图像。代码在 Chrome 中正确显示图像,但在 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;
}
}
}
【问题讨论】:
-
您是否考虑过使用library to handle thumbnail generation?如果您正在做自己的处理程序,请check out the list if no-nos 避免。
-
我有一段时间没有积极开发该代码,但我认为使用库(如您的建议)是可行的方法。谢谢!