views:

335

answers:

4

Greetings!

I'm scratching my head, wondering why when I do the following:

Response.Redirect(@"http://www.example.com/file.exe?id=12345");

Both IE6 and IE7 will download the file as "file" (with no extension), but Firefox, Opera, Google Chrome and Safari have no problems at all downloading the file as "file.exe".

Any idea what IE6/7's problem is and how can I fix this?

+2  A: 

Have You tried to set correct content-type in Your response headers? For example:

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="file.exe"
Falco Foxburr
A: 

I've tried this:

Response.AddHeader("Content-Type", "application/octet-stream");
string disp = String.Format("attachment; filename={0}", fileName); // fileName = file.exe
Response.AddHeader("Content-Disposition", disp);
Response.Redirect(@"http://www.example.com/file.exe?id=12345");

But to no avail.

Bullines
This code will just issue a 302 to http://www.example.com/file.exe?id=12345 which will be processed as normal, can you not set these headers when you actually stream the file to the client
Andrew Cox
If the downloadable EXEs are hosted on another server in the same domain, how would I go about this?
Bullines
A: 

You will probably need to get the filesize remotely and add it to Content-Length on the header section.

Unfortunately, the files are hosted on another server in the same domain.
Bullines
A: 

If you use fiddler2 (http://www.fiddler2.com/fiddler2/) you can see exactly what headers are getting sent to IE which may help you in debugging.

Perhaps you can post the resulting headers here?

I doubt that adding the Content-Type and Content-Disposition prior to the redirect will have any affect, since the browser sees the redirect header and makes a completely new http request to the redirected url, which will be an entirely different set of headers.

However, you might try a Server.Transfer which is a server side redirect, something like the following:

Response.Clear(); //In case your .aspx page has already written some html content
Response.AddHeader("Content-Type", "application/octet-stream");
string disp = String.Format("attachment; filename={0}", fileName); // fileName = file.exe
Response.AddHeader("Content-Disposition", disp);

Server.Transfer(@"http://www.example.com/file.exe?id=12345");

Or alternatively, use Response.BinaryWrite :

Response.Clear(); //In case your .aspx page has already written some html content
byte[] exeContent = ... //read the content of the .exe into a byte[]

Response.AddHeader("Content-Type", "application/octet-stream");
string disp = String.Format("attachment; filename={0}", fileName); // fileName = file.exe
Response.AddHeader("Content-Disposition", disp);

Response.BinaryWrite(exeContent);
Nathan