I am storing images in a database and I am using an image handler to display the images using the file path + id. The problem I have is when I update the image through the page, the image doesn't change. Wierd thing is I don't have this problem with firefox or chrome.
ASHX handler
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);
}
}
User control code
string imagePath = "<a href=" + (Image.ImageUrl = "~/ShowImage.ashx?id=" + r["Image_id"]);
Markup
<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>
I am not sure what other code to post but here is what I think is relevant. When I click my button to update an image it successfully updates the row in the database. Also I can update data about an image and this correctly updates.
Any ideas?
What I ended up doing is using a guid as my image id in my Image handler. But in my SQL, when I update an image I use sql servers in-built newid() function so everytime an update is made that images guid will change. By doing this IE recognises that its not the same ID and doesn't use the cached image.