0
好吧,我一直在这个工作不停,并做了大量的搜索。从数据库中拉出图像时无法显示图像。如果我尝试去手动处理链接,我会收到一条消息,指出“图像[Image]无法显示,因为它包含错误”。我之前在数据库中有一些旧图像,并首先正确显示这些图像。但现在,如果我更新图像,它会给我这个错误,当试图查看它们。HttpHandler [Image]无法显示,因为它包含错误
上传代码。
if (fileuploadImage.HasFile)
{
if (IsValidImage(fileuploadImage))
{
int length = fileuploadImage.PostedFile.ContentLength;
byte[] imgbyte = new byte[length];
HttpPostedFile img = fileuploadImage.PostedFile;
img.InputStream.Read(imgbyte, 0, length);
if (mainImage == null)
{
ProfileImage image = new ProfileImage();
image.ImageName = txtImageName.Text;
image.ImageData = imgbyte;
image.ImageType = img.ContentType;
image.MainImage = true;
image.PersonID = personID;
if (image.CreateImage() <= 0)
{
SetError("There was an error uploading this image.");
}
}
else
{
mainImage.ImageName = txtImageName.Text;
mainImage.ImageType = img.ContentType;
mainImage.ImageData = imgbyte;
mainImage.MainImage = true;
mainImage.PersonID = personID;
if (!mainImage.UpdateImage())
{
SetError("There was an error uploading this image.");
}
}
}
else
{
SetError("Not a valid image type.");
}
这里是我的图像处理程序:
public class ImageHandler : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
int imageid = Parser.GetInt(context.Request.QueryString["ImID"]);
ProfileImage image = new ProfileImage(Parser.GetInt(imageid));
context.Response.ContentType = image.ImageType;
context.Response.Clear();
context.Response.BinaryWrite(image.ImageData);
context.Response.End();
}
这是如何我称它 “?〜/ ImageHandler.ashx IMID =” + Parser.GetString(image.ImageID)
我正在使用数据类型图像在sql服务器来存储此。
编辑:
我还发现,如果我把周围context.Response.end(一个尝试catch)它示数出来说“无法评估的代码,因为本地帧...”
也许MemoryStream没有被重置到原来的位置? –