i’m trying to display an image from the database in an ASP.NET web page. I’m using a generic handler, and it works fine on firefox, chrome and IE9, but not in IE8. That’s my generic handler code:
public void ProcessRequest(HttpContext context)
{
byte[] FileContent = null;
if (context.Request.QueryString["imagen"] != null)
{
FileContent = GetImageFromDatabase(context.Request.QueryString["imagen"]);
context.Response.ContentType = "image/png";
context.Response.BinaryWrite(FileContent);
}
}
And i have an image in my asp page markup:
<asp:Image ID="imgInicio" runat="server" Width="100%" AlternateText="Inicio" />
Finally i call this on the load event;
imgInicio.ImageUrl = String.Format(@"~/ShowImage.ashx?imagen={0}", idImage);
I have tried it all. Any help would be appreciated.
Problem solved
I found the solution. I don´t know why in Internet Explorer 8 you have to specify the format of the image. I had to write code to format it using System.Drawing namespace. I added a helper class with the following methods:
And then i call the mehod inside the handler:
I think that, when we convert the bytes to a System.Drawing.Image and then use the Save method to retrieve the bytes again, the framework does something, maybe add or remove some bytes, that other browsers ignore, but they are important to Internet Explorer 8. That’s what i think, but it’s not certain. The thing is that it works for me