IE 错误?使用 IHttpHandler 从数据库检索图像,获取随机空白图像

发布于 2024-09-28 07:03:49 字数 1830 浏览 1 评论 0原文

我正在使用 ASP.net/C# 并尝试构建一个图片库。我的图像作为字节数据存储在数据库中,并且使用像 getDocument.axd?attachmentID= X 这样的 axd 文件来设置 Image 对象,然后在页面加载时将其添加到 aspx 页面。

在 IE 中,大多数图像都会渲染到页面,但某些图像不会渲染,我会得到默认的红色 x 图像。有趣的是,当我查看图像的属性时,它没有文件类型。我检索的文件都是 jpg 的。

我希望有人可以提供帮助,因为这是一个真正令人头疼的问题:)

我必须注意,这个问题不会出现在 firefox/chrome 中,并且所有图像都会正确渲染。

void IHttpHandler.ProcessRequest(HttpContext context)
    {

        if (context.Request.QueryString["attid"] != null)
        {
            int attid = int.Parse(context.Request.QueryString["attid"]);

            context.Response.Clear();
            context.Response.AddHeader("Content-Length", att.AttachmentData.Length.ToString());
            context.Response.ContentType = att.MimeType.MimeHeader;
            //context.Response.CacheControl = "no-cache";
            context.Response.AddHeader("Content-Disposition", "attachment; filename=" + att.FileName.Replace(" ", "_") + "." + att.MimeType.FileExtension + ";");
            context.Response.OutputStream.Write(att.AttachmentData, 0, att.AttachmentData.Length);
            context.Response.End();

            return;
        }
    }

为了调用这个方法,我从数据库获取一个 ids 列表,并执行以下操作拉回相应的图像;

            foreach (int i in lstImages)
            {
                Image tempImage = new Image();
                Panel pnl = new Panel();
                tempImage.ImageUrl = "getDocument.axd?attid=" + i;
                tempImage.Attributes.Add("onclick", "javascript:populateEditor(" + i + ");");
                tempImage.Height = 100;
                tempImage.Width = 100;
                pnl.Controls.Add(tempImage);
                divImages.Controls.Add(tempImage);
            }

* 编辑 * 我的一位同事注意到我的一些图像的图像文件中包含奇怪的标题信息。我们怀疑这可能是 Photoshop 保存文件造成的,因为所有不是由特定人员创建的文件似乎都显示正常。

I'm using ASP.net/C# and trying to build an image gallery. My images are stored as byte data in the database and im using an axd file like so, getDocument.axd?attachmentID= X, to set an Image object which is then added to the aspx page on page load.

In IE most of the images are rendered to the page however certain images arn't rendered i get the default red x image. Interestingly when i view the properties of the image it does not have a file type. The files that im retrieving are all jpg's.

I hope someone can help because this is a real head scratcher :)

I must note that this issue does not occur in firefox/chrome and all images render correctly.

void IHttpHandler.ProcessRequest(HttpContext context)
    {

        if (context.Request.QueryString["attid"] != null)
        {
            int attid = int.Parse(context.Request.QueryString["attid"]);

            context.Response.Clear();
            context.Response.AddHeader("Content-Length", att.AttachmentData.Length.ToString());
            context.Response.ContentType = att.MimeType.MimeHeader;
            //context.Response.CacheControl = "no-cache";
            context.Response.AddHeader("Content-Disposition", "attachment; filename=" + att.FileName.Replace(" ", "_") + "." + att.MimeType.FileExtension + ";");
            context.Response.OutputStream.Write(att.AttachmentData, 0, att.AttachmentData.Length);
            context.Response.End();

            return;
        }
    }

In order to call this method i get a List of ids from the db and pull back the corresponding images doing the following;

            foreach (int i in lstImages)
            {
                Image tempImage = new Image();
                Panel pnl = new Panel();
                tempImage.ImageUrl = "getDocument.axd?attid=" + i;
                tempImage.Attributes.Add("onclick", "javascript:populateEditor(" + i + ");");
                tempImage.Height = 100;
                tempImage.Width = 100;
                pnl.Controls.Add(tempImage);
                divImages.Controls.Add(tempImage);
            }

* EDIT *
A colleague of mine noticed that some of my images had strange header information contained in the image file. We suspect that this might be from photoshop saving files as all files which have not been created from a specific person seem to display fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别低头,皇冠会掉 2024-10-05 07:03:49

我自己这样做过,从未遇到过这个问题。这种情况是针对相同的图像发生还是半随机的?

检查 jpeg 在 IE 中是否正常可见(即作为源文件而不是通过处理程序),使用 fiddler 检查 HTTP 流量,并检查输出的字节流看起来是否正常。

Having done this myself I've never encountered this problem. Does this occur for the same image(s) or is it semi-random?

Check the jpegs are viewable in IE normally (i.e. as a source file not through your handler), check the HTTP traffic with fiddler, and check the bytestream going out looks good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文