Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Response.WriteBinary ->  IE 7 security download blocker issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Earthbound - 25 Apr 2008 20:09 GMT
Hello,

I have a a web page where users can choose, via links, in what format they
want to see results in: PDF, XPS, HTML, or downloadable ZIP file.
I do not have any issues with any of the processes other than the ZIP file
and that problem occures in the Browser, IE 7.
This problem has been tested with IE 7 on Vista x64, Vista x86, XP x64 and
XP x86.
Os here doesn't seem to be the issue as this problem occures in all these
versions of IE 7.

NOTE: This is NOT a problem with Firefox as it is working there as expected.

The page I have uses a Javascript postback (AJAX) to notify itself of which
link was selected. The post back then does a Response.Redirect to the page
responsible for creating the document or download in this case that the user
wants.

The PDF and ZIP process are basically identical to each other, other that
the file type it delivers to the client browser.

The issues is that when the user selects the ZIP download link the IE 7
Browser displays the security bar giving the download warning bar at the top
of the page. This requires the user to confirm that they are trying to
download a file by clicking on the ".. Click her for options" and then
"Download this file" from the menu.
This is very normal. However the download never occures, it is as if IE 7
abandons it and just refresh the page.

If the user subseqently clicks on the link again while still at the page the
down happens WITHOUT the security bar interferance and the user gets the
standard File Download Dialog box. The download then occures successfully
and the ZIP file. It is worth noting that the zip file and it's contents are
not corrupt or otherwise displaying issues.

Here is what the basic code looks like in my ASP.net page, again note that
this code is identical in my PDF download page and it works without the
problem discribed above.
(vista x64 VS08 is my current build/test environment)

   HttpResponse r = this.Context.Response;
   r.ClearContent();
   r.ClearHeaders();
   r.Clear();
   r.AppendHeader("Content-Type", "application/zip");
   r.AppendHeader("Content-Length", buffer.Length.ToString());
   r.AppendHeader("Content-Disposition", "attachment; filename=" +
FileName.ToString() + ".zip");
   r.BinaryWrite(buffer);
   r.Flush();
   r.End();

NOTE: Have tried every many variations of the Content-Type using one or more
of them in my testing which made no difference as far as the discribed
problem.

I have spent several hours trying to find a way to resolve this and have
researched many forums and KB's to find an answer but, to with no luck

PLEASE some point me to something that can help. I am at my wits end in
trying to find a solution, without having to resort to telling all of our
customer the we prefer that they use Firefox at our web site in order to
overcome this issue with IE 7.

I would really like to understand why the PDF file downsloads after the
security bar and the Zip file does not!

Your help is greatly appreciated.

MANY MANY Thanks!
Alexey Smirnov - 25 Apr 2008 20:25 GMT
> Hello,
>
[quoted text clipped - 66 lines]
>
> MANY MANY Thanks!

Instead of  "application/zip" in r.AppendHeader("Content-Type",
"application/zip"); try either

application/x-compressed
application/x-zip-compressed
application/x-gzip-compressed

http://msdn2.microsoft.com/en-us/library/ms775147.aspx
Alexey Smirnov - 25 Apr 2008 20:28 GMT
> > Hello,
>
[quoted text clipped - 75 lines]
>
> http://msdn2.microsoft.com/en-us/library/ms775147.aspx

either... or application/force-download or application/octet-stream...
Earthbound - 25 Apr 2008 20:41 GMT
On Apr 25, 9:09 pm, "Earthbound" <Jo...@holdown.com> wrote:
> Hello,
>
[quoted text clipped - 73 lines]
>
> MANY MANY Thanks!

Instead of  "application/zip" in r.AppendHeader("Content-Type",
"application/zip"); try either

application/x-compressed
application/x-zip-compressed
application/x-gzip-compressed

http://msdn2.microsoft.com/en-us/library/ms775147.aspx

Thank you Alexey, however as I indicated in my message I have tried every
flavor of  of Content-Type including those that you have provided and no
changes in the problem. Again tested on all those diffent OS'es with IE 7.
This one is a bloody stumpper...
Alexey Smirnov - 25 Apr 2008 22:13 GMT
> On Apr 25, 9:09 pm, "Earthbound" <Jo...@holdown.com> wrote:
>
[quoted text clipped - 91 lines]
>
> - Show quoted text -

It seems that the problem was in missing Content-Encoding

using (System.IO.FileStream fs = new System.IO.FileStream(
@"C:\Temp\Test.zip",
System.IO.FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, (int)fs.Length);

HttpResponse r = this.Context.Response;
r.ClearContent();
r.ClearHeaders();
r.Clear();
r.AppendHeader("Content-Type", "application/octet-stream");
//r.AppendHeader("Content-Length", buffer.Length.ToString());
r.AppendHeader("Content-Encoding", "gzip");
r.AppendHeader("Content-Disposition", "attachment;
filename=Test.zip");
r.BinaryWrite(buffer);
r.Flush();
r.End();
}

In this case browser get following response from the server

HTTP/1.1 200 OK
...
Content-Encoding: gzip
Content-Disposition: attachment; filename=test.zip
Content-Type: application/octet-stream

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.