2
Answers

IIS7 with ASP.NET + Response.OutputStream.Write does not work in IE7 and IE8

wai kit kan

wai kit kan

15y
13.8k
1

Hi all.
 
So here is my problem. The application is hosted in Windows Server 2008 with IIS7.
 
I have a button (from Silverlight page) that calls a new webpage (asp.net page, ext .aspx) that contains
Response.OutputStream.Write(blahblahblah) which then should prompt a download box to allow user to save an image.
 
Now the page basically creates a stream and then is supposed to output the stream to the user using
Response.Outputstream.Write.
 
Then the user is supposed to be prompted to open or save the document.  This works fine in Firefox but it does not
work with IE7 or 8
 
Also this exact same code works with IIS6 on a Windows 2003 server.
 
So the only differences is the IIS6 and Windows 2003 Server to IIS7 and Windows 2008 Server.
 
And what happens is when I clicked the button, the page did pop up but disappear 1-2 seconds later without
prompting the download box to the user.
 
Here is the code that launches for Reference
 
//e.g file = 123424_43535.jpeg
FileInfo myFile = new FileInfo(Server.MapPath("mapImage/") + file;
using(var fs = myFile.Open(FileMode.Open, FileAccess.Read))
{
    byte[] buffer;
    int read;
    buffer = new byte[(int)fs.Length];
    Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
    Response.ContentType = "application/x-force-download";
    Response.AddHeader("Connection", "Keep-Alive");
    Response.AddHeader("Content-Length", fs.Length.ToString());
    while((read = fs.Read(buffer, 0, buffer.Length)) > 0)
    {
        this.Response.OutputStream.Write(buffer, 0, read);
    }
}
Response.End();
 
I have tried to replace Response.AddHeader with Response.AppendHeader, however the result is still the same.
Also, I have tried to replace the Response.ContentType with application/octet-stream and image/jpeg, I also faced
the same result.
 
Is there any setting/modification on server/code that I need to look on?
 
This problem has bugged me for a long period and a quick reply/solution will be very much appreciated.
 
Thanks and have a nice day.
 
Regards,
Kent
Answers (2)