2012-04-17 79 views
2

我将图像存储在数据库中,我使用图像处理程序使用文件路径+ ID显示图像。我遇到的问题是当我通过页面更新图像时,图像不会改变。奇怪的是我没有这个问题与Firefox或铬。ASHX图像处理程序不在ie中工作,在Firefox和Chrome中工作

ASHX处理程序

public void ProcessRequest(HttpContext context) 
    { 
     Guid image_id; 
     if (context.Request.QueryString["id"] != null) 
      image_id = System.Guid.Parse(context.Request.QueryString["id"]); 
     else 
      throw new ArgumentException("No parameter specified"); 

     context.Response.ContentType = "image/jpeg"; 
     Stream strm = GetImageFromDatabase(image_id); 
     if (strm != null) 
     { 
      byte[] buffer = new byte[4096]; 
      int byteSeq = strm.Read(buffer, 0, 4096); 

      while (byteSeq > 0) 
      { 
       context.Response.OutputStream.Write(buffer, 0, byteSeq); 
       byteSeq = strm.Read(buffer, 0, 4096); 
      } 
      //context.Response.BinaryWrite(buffer); 
     } 
    } 

用户控制代码

string imagePath = "<a href=" + (Image.ImageUrl = "~/ShowImage.ashx?id=" + r["Image_id"]); 

标记

<asp:UpdatePanel ID="Upd1" runat="server" UpdateMode="Always" > 
    <ContentTemplate> 
     <div id="mpe" style="width: 600px; padding: 5px;"> 
      <uc2:IMG ID="IMG1" cssclass="bodycopy" runat="server" /> 
     </div> 
     <asp:UpdateProgress ID="upp1" runat="server" AssociatedUpdatePanelID="Upd1"> 
      <ProgressTemplate> 
       <div id="progressBackgroundFilter"> 
       </div> 
       <div id="modalPopup"> 
        &nbsp; &nbsp; Loading... 
        <img align="middle" src="../images/Ajax/loading_1.gif" /> 
       </div> 
      </ProgressTemplate> 
     </asp:UpdateProgress> 
    </ContentTemplate> 
</asp:UpdatePanel> 

我不知道张贴什么其他的代码,但这里是我认为是相关的。当我点击我的按钮更新图像时,它会成功更新数据库中的行。此外,我可以更新有关图像的数据并正确更新。

任何想法?

+0

你可以核对一下页面** ** IE使用**开发工具**,检查图像是否存在或不?? – 2012-04-17 13:45:02

+0

图像显示在ie页面加载时,当我更新图像时,我看到旧图像,而不是新图像,如果有意义的话? – 2012-04-17 13:47:52

+0

这可能是由于缓存..请看看这个** http://superuser.com/questions/81182/how-to-force-internet-explorer-ie-to-really-reload-the-page* * – 2012-04-17 13:49:38

回答

0

我最终什么事是使用做一个GUID在我的图片处理我的图片ID。但在我的SQL中,当我更新图像时,我使用sql server内置的newid()函数,因此每次更新图像guid都会改变。通过这样做,IE可以识别出它不是相同的ID,并且不使用缓存的图像。

0

你可以尝试使用这段代码吗?

string imagePath = "<a href='" + Page.ResolveClientUrl("~/ShowImage.ashx?id=" + r["Image_id"]) + "' />"; 
1

IE缓存数据,并显示相同的URL如果URL不变。我也面临同样的问题,并删除它与下面的技巧: -

imgUser.ImageUrl = "Handler.ashx?UserID=" + Convert.ToString(Session["userid"]) + "extraQS=" + DateTime.Now.Second; 

的extraQS查询字符串DateTime.Now.Second将通过使URL动态做出的伎俩,因此URL将更改每个请求和图像不会从浏览器缓存中使用。

注意: - 忽略Handler.ashx中额外的查询字符串参数。

0

该问题可以通过在QueryString的末尾添加当前秒或随机数来解决。它的工作正常IE浏览器。

string imagePath = "<a href=" + (Image.ImageUrl = "~/ShowImage.ashx?id=" + r["Image_id"] + "&timeInSec="+ DateTime.Now.Second); 

另一个例子返回图片URL

protected string getImageURL(int index) 
     { 
      return "ImageHandler.ashx?index=" + index + "&timeInSec=" + DateTime.Now.Second; 
     } 
相关问题