Chrome 浏览器不显示 HTTP 处理程序生成的图像

2024-05-17

基本上我有一个网站,可以呈现一些文档(主要是办公室)的 HTML 预览。生成的 HTML 片段包含在同一网站返回的页面中,但图像由 HTTP 处理程序从具有以下链接的另一个网站返回:

<img width="50" height="50" src="http://portal/Service/GetFile.asxh?id=123&inline=true">

由于某种原因,除 Chrome 之外的所有浏览器(例如 IE6/7/8、Firefox、Opera、Safari)都显示一切正常,但是对于这些图像,Chrome 显示“损坏的图像”图标。如果我选择“在新选项卡中打开图像”,则图像显示得很好。

Edit我以为我已经解决了这个问题,但显然在打开 Fiddler 的情况下它工作得很好。

我在代码中留下了 context.Response="utf-8" ,但是删除它没有什么区别。

Headers:

HTTP/1.1 200 OK
Date: Wed, 05 Jan 2011 14:26:57 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Transfer-Encoding: chunked
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: image/jpeg

Code:

                    context.Response.ContentType = file.ContentType;

                    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    byte[] buff = new byte[BuffSize];
                    using (var stream = repository.GetFileContentsAsStream(file.ContentId))
                    {
                        int bytesRead;
                        do
                        {
                            bytesRead = stream.Read(buff, 0, BuffSize);
                            if (bytesRead > 0)
                            {
                                context.Response.OutputStream.Write(buff, 0, bytesRead);
                            }
                        } while (bytesRead > 0);
                    }

                    context.Response.Flush();
                    context.Response.Close();

我很确定 Chrome 需要为图像设置长度,因此在处理图像时尝试将 Content-Length 标头添加到您的响应中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Chrome 浏览器不显示 HTTP 处理程序生成的图像 的相关文章