使用查询字符串参数和IE6 / 7重定向到EXE

时间:2022-06-01 21:25:14

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".

IE6和IE7都将文件下载为“文件”(没有扩展名),但Firefox,Opera,谷歌Chrome和Safari都没有问题,将文件下载为“file.exe”。

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

知道IE6 / 7的问题是什么,我该如何解决这个问题?

3 个解决方案

#1


2  

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"

#2


0  

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

您可能需要远程获取文件大小并将其添加到标题部分的Content-Length。

#3


0  

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.

如果您使用fiddler2(http://www.fiddler2.com/fiddler2/),您可以确切地看到哪些标头被发送到IE,这可能有助于您进行调试。

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.

我怀疑在重定向之前添加Content-Type和Content-Disposition会产生任何影响,因为浏览器会看到重定向标头并向重定向的URL发出一个全新的http请求,这将是一组完全不同的标头。

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

但是,您可以尝试Server.Transfer,它是服务器端重定向,如下所示:

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.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);

#1


2  

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"

#2


0  

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

您可能需要远程获取文件大小并将其添加到标题部分的Content-Length。

#3


0  

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.

如果您使用fiddler2(http://www.fiddler2.com/fiddler2/),您可以确切地看到哪些标头被发送到IE,这可能有助于您进行调试。

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.

我怀疑在重定向之前添加Content-Type和Content-Disposition会产生任何影响,因为浏览器会看到重定向标头并向重定向的URL发出一个全新的http请求,这将是一组完全不同的标头。

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

但是,您可以尝试Server.Transfer,它是服务器端重定向,如下所示:

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.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);