显示aspx GET请求返回的图像

时间:2010-01-12 14:39:08

标签: c# asp.net internet-explorer image

我正在尝试显示像这样的

这样的aspx页面返回的图像
<asp:Image ID="ButtonImage" runat="server" 
         Width="200" 
         Height="113" 
         BackColor="LightGray" 
         ImageUrl="/Editor/OpenMedia.aspx?path=336!TestImage.jpg"/>

OpenMedia.aspx

public partial class OpenMedia : MemberPage
{
    protected void Page_Init(object sender, EventArgs e)
    {
       string path = Request.QueryString["path"];
       HASFile file = new HASFile(path);

       HASConnection con = new HASConnection(ConfigurationManager.AppSettings["HASUrl"]);
       HASReader reader = new HASReader(con);

       reader.getFile(file, Response.OutputStream);
       Response.ContentType = "image/jpeg"; 
    }
}

当我用fiddler查看响应时,图像被正确返回,它在Firefox中正常工作,但在IE中却无法正常工作。为什么这不适用于IE?

2 个答案:

答案 0 :(得分:0)

尝试反转序列:

protected void Page_Init(object sender, EventArgs e) 
{ 
   Response.ContentType = "image/jpeg";  

   string path = Request.QueryString["path"]; 
   HASFile file = new HASFile(path); 
   HASConnection con = new HASConnection(ConfigurationManager.AppSettings["HASUrl"]); 
   HASReader reader = new HASReader(con); 

   reader.getFile(file, Response.OutputStream); 
} 

答案 1 :(得分:0)

事实证明,我测试的一些图像在某种程度上是因为Internet Explorer无法解决的。 Firefox可以显示图像,即使它们已损坏。

相关问题