Question about Module Handler for dynamically renderring an image.

K

Ken Varn

I am using an HttpModule handler to dynamically stream out a JPEG image to
an <img> control. It seems to work fine except for one thing. If I try to
save the image in IE using the "Save Picture..." selection, IE does not
recognize that the image is a JPEG. Instead, it tries to save it as a BMP.
Is there something that I need to send in the response header to make IE
recognize that the image is a JPEG? I am hoping that the ASPX extension is
not what is throwing it off.

Here is a snippet of what I am doing.


HTML
<img src="MyVirtualUrl.aspx">


C# Server Side.

MemoryStream MemStream = new MemoryStream();

//
// ImgData is built in here as a Byte[] array. Details omitted
for space.
//

MemStream.Write(ImgData.Data,0,ImgData.Data.Length);
MemStream.WriteTo(context.Response.OutputStream);
MemStream.Close();

context.Response.Cache.SetNoServerCaching();

context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(new
DateTime(1900,01,01,00,00,00,00));

context.ClearError();
context.Response.ContentType = "image/JPEG";
context.Response.StatusCode = 200;
context.Response.Flush();

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
G

Guest

Ken,
I have this in my code (which works)
context.Response.ContentType = "image/jpeg";
context.Response.AddHeader("Content-Disposition","inline;filename=myimage.jpg");

- Sergio Pereira
 
K

Ken Varn

Hmmm. I tried this out, but it didn't work for me. If I select Save
Picture As..., the dialog displays "untitled" for the filename and Bitmap
(bmp) for the file type.

Are you sure that this is all you had to do to get it to work?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Sergio Pereira said:
Ken,
I have this in my code (which works)
context.Response.ContentType = "image/jpeg";
context.Response.AddHeader("Content-Disposition","inline;filename=myimage.jp
g");

- Sergio Pereira

Ken Varn said:
I am using an HttpModule handler to dynamically stream out a JPEG image to
an <img> control. It seems to work fine except for one thing. If I try to
save the image in IE using the "Save Picture..." selection, IE does not
recognize that the image is a JPEG. Instead, it tries to save it as a BMP.
Is there something that I need to send in the response header to make IE
recognize that the image is a JPEG? I am hoping that the ASPX extension is
not what is throwing it off.

Here is a snippet of what I am doing.


HTML
<img src="MyVirtualUrl.aspx">


C# Server Side.

MemoryStream MemStream = new MemoryStream();

//
// ImgData is built in here as a Byte[] array. Details omitted
for space.
//

MemStream.Write(ImgData.Data,0,ImgData.Data.Length);
MemStream.WriteTo(context.Response.OutputStream);
MemStream.Close();

context.Response.Cache.SetNoServerCaching();

context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(new
DateTime(1900,01,01,00,00,00,00));

context.ClearError();
context.Response.ContentType = "image/JPEG";
context.Response.StatusCode = 200;
context.Response.Flush();

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top