views:

52

answers:

2

We have a .NET executable that we are hosting on a web server. The domain for the web server is set as a "Trusted Site" on the user's IE.

When the user left clicks the link for the executable, it blows up with the error: "Microsoft IE Execute shell has encountered a problem and needs to close". From what I have read, it is because IE is trying to execute the file directly using ieexec.exe.

What is desired, is the user should get a pop-up box with a security warning asking them if they want to download the .exe, and buttons "Run" "Save" "Cancel". Not a cryptic security exception. The workaround is to right-click and click on "Save Target As..".

Of course, this only blows up in IE, not Firefox or Chrome.

How can I compile the .NET executable to bypass this ieexec.exe and force the file download prompt?

A: 

It may not be the easiest solution, but I believe it should work: redirect the file to a script, and have that script set the content-disposition header and output the file. In case that wasn't clear, I'll provide a step-by-step below. In the step-by-step I'll assume usage of an apache with php environment, but the same should be possible in any decent environment.

First, we will set up a mod_rewrite rule on your web server to have the download get passed to a php file:

.htaccess

RewriteEngine On
RewriteRule ^file.exe$ file.php

Then, we will make have the php file set the appropriate headers, include the content-disposition header and include the file.

file.php

<?php

header("Content-disposition: attachment; filename=file.exe");
header("Content-type: application/octet-stream");

require 'file.exe';
?>

And that should tell the browser not to consider anything other than downloading it. I haven't tried if IE respects the header correctly, but this way you are telling it to download the file in question.

Jasper
-1: Why would you assume Apache, or PHP?
John Saunders
@John Saunders: Because the actual information wasn't given and both are most common. On top of that, this is really about the strategy of handling it, not about the actual code, so if I give the code for apache and php, it should be doable for the rugcutter to apply the same strategy to whatever environment he is using.
Jasper
@John Saunders: I could instead have said "redirect the file to a script, in which you set the content-disposition header and then output the file", however, this is much more tangible, even when not using these particular languages.
Jasper
@John Saunders: I updated the answer to more closely reflect that the solution is an example and that the assumptions are just an example of how one would achieve that. Better?
Jasper
@Jasper: no, it's not. Bringing PHP into a .NET discussion makes little or no sense.
John Saunders
@John Sounders: Actually, relating the .NET part to the web server makes no sense. The question was about a .NET application hosted on _a web server_ with no further specification of that server. Having made .NET application indicates that you _might_ use a .NET web server, but using a web server indicates that you _might_ use PHP. Saying anything about a .NET server is just as much guessing as saying anything about PHP is.
Jasper
+2  A: 

Without knowing what specific .NET technology you have access to, it is difficult to be sure of an answer, however, you may find this helpful.

If you are serving the content in ASP.NET, you can set the content disposition and content type to encourage correct treatment from the browser:

Response.AppendHeader("content-disposition", "attachment; filename=myexe.exe");
Response.ContentType = "application/octet-stream";

Here is an old, but reasonably applicable example online of controlling the HttpResonse in ASP.NET:

http://aspalliance.com/259

kbrimington