【发布时间】:2012-04-17 13:40:49
【问题描述】:
我将图像存储在数据库中,并使用图像处理程序通过文件路径 + id 显示图像。我遇到的问题是当我通过页面更新图像时,图像不会改变。奇怪的是我在使用 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">
Loading...
<img align="middle" src="../images/Ajax/loading_1.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
我不确定要发布哪些其他代码,但这是我认为相关的代码。当我单击按钮更新图像时,它成功更新了数据库中的行。我还可以更新有关图像的数据,并且可以正确更新。
有什么想法吗?
【问题讨论】:
-
你能不能用开发者工具查看IE中的页面,看看有没有图片??
-
当我更新图像时,图像显示在加载它的页面上,我看到的是旧图像而不是新图像,如果有意义的话?
-
这可能是由于缓存的原因。请看看这个superuser.com/questions/81182/…
-
我还应该指出,当我删除更新面板时,这个问题不存在。但我使用更新面板来控制更新进度。
标签: asp.net updatepanel httphandler