Asp.net ASHX图像处理程序不适用于ie,适用于firefox和chrome

Asp.net ASHX图像处理程序不适用于ie,适用于firefox和chrome,asp.net,updatepanel,httphandler,Asp.net,Updatepanel,Httphandler,我将图像存储在数据库中,并使用图像处理程序使用文件路径+id显示图像。我遇到的问题是,当我通过页面更新图像时,图像不会更改。Wierd的问题是,我对firefox或chrome没有这个问题 ASHX处理器 public void ProcessRequest(HttpContext context) { Guid image_id; if (context.Request.QueryString["id"] != null) ima

我将图像存储在数据库中,并使用图像处理程序使用文件路径+id显示图像。我遇到的问题是,当我通过页面更新图像时,图像不会更改。Wierd的问题是,我对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"]);

string imagePath=“您能尝试使用此代码吗

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

我最后做的是在映像处理程序中使用guid作为映像id。但在SQL中,当我更新映像时,我在内置的newid()中使用SQL Server函数,以便每次更新时图像guid都会更改。通过这样做,IE会识别出它的ID不同,并且不会使用缓存的图像。

IE会缓存数据,如果URL没有更改,则会显示相同的内容。我也面临同样的问题,并使用以下技巧将其删除:-

imgUser.ImageUrl = "Handler.ashx?UserID=" + Convert.ToString(Session["userid"]) + "extraQS=" + DateTime.Now.Second;
带有DateTime.Now.Second的extraQS查询字符串将使URL成为动态的,因此URL将在每次请求时更改,并且不会从浏览器缓存中使用图像


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

该问题可以通过在QueryString的末尾添加当前秒数或随机数来解决。它对IE很有效

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

你能使用开发者工具检查IE中的页面并检查图像是否存在吗?当我更新一个图像时,图像显示在IE的加载页面上,我看到的是旧图像,而不是新图像,如果这有意义的话?这可能是由于缓存。请看一看,我还应该指出,当我删除更新面板时这是一个不存在的问题。但我使用更新面板来控制更新进度。
string imagePath = "<a href=" + (Image.ImageUrl = "~/ShowImage.ashx?id=" + r["Image_id"] + "&timeInSec="+ DateTime.Now.Second);
protected string getImageURL(int index)
        {
            return  "ImageHandler.ashx?index=" + index + "&timeInSec=" + DateTime.Now.Second;
        }