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

标签 asp.net html google-chrome

基本上我有一个网站可以呈现一些文档(主要是办公室)的 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 显示“图像损坏”图标。如果我选择“在新选项卡中打开图像”,那么图像就会正常显示。

编辑 我以为我已经解决了这个问题,但显然在打开 Fiddler 的情况下它工作正常。

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

标题:

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

代码:

                    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 header 添加到您的响应中。

关于asp.net - Chrome 浏览器不显示 HTTP 处理程序生成的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4604804/

相关文章:

c# - 跨多个网站共享用户控件

asp.net - 使用表单例份验证注销从不同浏览器/计算机登录的用户

javascript - 从另一个 DropDownList 填充 DropDownList

html - 为什么 nth-of-type 不适用于包含在 a 标签中的图像?

javascript - 在 Chrome 扩展内容脚本中共享内存对象?

javascript - 在同一行的复选框选中/未选中时启用 GridViewRow 中的 DropDownList(使用任何 c#、jquery、javascript)

javascript - "String"类型的 IndexedDB 键可以是 url 路径吗?

jquery - jquery中如何使用焦点?

css - 在 Chrome 中查看时,小设备尺寸的媒体查询不起作用

firefox - 适用于所有浏览器(Chrome、IE9、Firefox)的 FTP 链接